yarn add post-loader --dev
const postLoader = require('post-loader')
module.exports = {
module: {
rules: [{
test: /\.md$/,
loader: 'post-loader'
}]
}
}
Given my-blog-post.md
:
---
title: hello there
---
post **body**
Yields:
{
"data": {
"title": "hello there",
"date": "2017-02-28T14:57:59.000Z"
},
"content": "post **body**",
"html": null
}
Which is require-able
in other files:
import post from './my-blog-post.md'
console.log(post.data.title)
//=> hello there
Note: We automatically set date
to the birthtime of the file if no date
is set in front-matter.
const postLoader = require('post-loader')
module.exports = {
module: {
rules: [{
test: /\.md$/,
loader: 'post-loader',
options: {
render(markdown) {
return someMarkdownParser.toHTML(markdown)
}
}
}]
}
}
Given the same markdown content as used above, it yields:
{
"data": {
"title": "hello there",
"date": "2017-02-28T14:57:59.000Z"
},
"content": "post **body**",
"html": "<p>post <strong>options</strong></p>\\\\n\\"
}
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
post-loader © egoist, Released under the MIT License.
Authored and maintained by egoist with help from contributors (list).
egoistian.com · GitHub @egoist · Twitter @_egoistlily