1
0
Fork 0
mirror of https://github.com/ipfs/awesome-ipfs.git synced 2024-11-20 11:28:35 -05:00
ipfs/scripts/make-readme.js
Henrique Dias a89015da98
feat: clean up (a lot) (#247)
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
2019-04-30 17:35:30 +01:00

43 lines
1.2 KiB
JavaScript

const fs = require('fs')
const path = require('path')
const files = require('./data')
const readme = path.join(__dirname, '../README.md')
const template = path.join(__dirname, 'readme-template.md')
const { slugify } = require('./utils')
const toc = files.map(cat => `- [${cat.title}](#${slugify(cat.title)})`).join('\n')
const sections = files.map(category => {
const content = category.content.map(item => {
let block = '- '
let mainUrl = ''
if (item.website) {
mainUrl = item.website
} else if (item.source) {
mainUrl = item.source
} else if (item.demo) {
mainUrl = item.demo
}
if (item.date) block += item.date + ': '
block += `[${item.title}](${mainUrl}) `
if (item.description) block += `- ${item.description.trim()}`
if (item.demo && mainUrl !== item.demo) {
if (!item.description) block += '-'
block += ` [Demo](${item.demo})`
}
if (item.source && mainUrl !== item.source) {
block += ` [Source](${item.source})`
}
return block
}).join('\n')
return `## ${category.title}\n\n${content}`
}).join('\n\n')
fs.writeFileSync(readme, fs.readFileSync(template)
.toString()
.replace('#PLACEHOLDER_TOC#', toc)
.replace('#PLACEHOLDER_CATEGORIES#', sections))