mirror of
https://github.com/ipfs/awesome-ipfs.git
synced 2024-11-27 11:37:23 -05:00
ab32206828
License: MIT Signed-off-by: Henrique Dias <hacdias@gmail.com>
50 lines
1.1 KiB
JavaScript
50 lines
1.1 KiB
JavaScript
const lunr = require('lunr')
|
|
const fs = require('fs-extra')
|
|
const { join } = require('path')
|
|
|
|
function getData () {
|
|
const data = require('./data')
|
|
|
|
data.push({
|
|
title: 'Awesome IPFS',
|
|
slug: '_index',
|
|
content: data
|
|
.reduce((arr, cat) => arr.concat(cat.content), [])
|
|
.map((el, i) => ({
|
|
...el,
|
|
index: i
|
|
}))
|
|
})
|
|
|
|
data.forEach(makeIndex)
|
|
return data
|
|
}
|
|
|
|
function makeIndex (category) {
|
|
const data = category.content.map(({ index, title, description = '', tags = [], category = '' }) => ({
|
|
ref: index,
|
|
data: `${title} ${description} ${tags.join(' ')} ${category}`
|
|
}))
|
|
|
|
category.index = lunr(function () {
|
|
this.ref('ref')
|
|
this.field('data')
|
|
data.forEach(this.add.bind(this))
|
|
})
|
|
}
|
|
|
|
const process = () => {
|
|
const dir = join(__dirname, '../src/content')
|
|
fs.ensureDirSync(dir)
|
|
fs.emptyDirSync(dir)
|
|
|
|
const data = getData()
|
|
|
|
for (const { index, slug, ...meta } of data) {
|
|
const filename = join(dir, slug + '.md')
|
|
fs.writeFileSync(filename, `${JSON.stringify(meta)}
|
|
<script>var idx = JSON.parse(\`${JSON.stringify(index).replace(`'`, `\\'`)}\`);</script>`)
|
|
}
|
|
}
|
|
|
|
process()
|