Skip to content

Instantly share code, notes, and snippets.

@hrb-suzuki hrb-suzuki/build.js
Last active Apr 9, 2019

Embed
What would you like to do?
const fs = require('fs')
const marked = require('marked')
const glob = require('glob')
const fm = require('front-matter')
const path = require('path')
const renderer = new marked.Renderer()
const fileNames = glob.sync(path.resolve('./contents/posts/*.md'))
const data = fileNames
.map(fileName => {
// Fileの中身を取得
const contents = fs.readFileSync(fileName, 'utf8')
// Front MatterでHeader部とBody部に分割
const { attributes, body } = fm(contents)
// BodyをMarkdown形式からHTMLに変換
const parsedBody = marked(body, { renderer })
return {
...attributes,
body: parsedBody
}
})
fs.writeFileSync('./dist/posts.json', JSON.stringify(data, null, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.