1
1
mirror of https://github.com/primer/css.git synced 2024-12-21 13:11:49 +03:00
css/lib/search-loader.js
2019-04-02 22:59:01 -07:00

14 lines
501 B
JavaScript

const grayMatter = require('gray-matter')
const fs = require('fs')
const {join} = require('path')
const searchIndex = {}
const searchIndexPath = join(process.cwd(), 'searchIndex.js')
module.exports = function(source) {
const {data, content} = grayMatter(source)
searchIndex[data.path] = Object.assign({title: data.title, path: data.path, keywords: data.keywords}, {content})
fs.writeFileSync(searchIndexPath, `export default ${JSON.stringify(searchIndex, null, 2)}`, 'utf8')
return source
}