https://github.com/egoist/post-loader
Webpack loader for blog posts written in Markdown.
https://github.com/egoist/post-loader
blog loader markdown post web webpack yaml
Last synced: about 1 year ago
JSON representation
Webpack loader for blog posts written in Markdown.
- Host: GitHub
- URL: https://github.com/egoist/post-loader
- Owner: egoist
- License: mit
- Created: 2017-02-28T15:02:12.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-12-25T14:15:14.000Z (over 4 years ago)
- Last Synced: 2025-04-20T09:44:56.416Z (about 1 year ago)
- Topics: blog, loader, markdown, post, web, webpack, yaml
- Language: JavaScript
- Homepage:
- Size: 69.3 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# post-loader
[](https://npmjs.com/package/post-loader) [](https://npmjs.com/package/post-loader) [](https://circleci.com/gh/egoist/post-loader) [](https://codecov.io/gh/egoist/post-loader) [](https://github.com/egoist/donate)
## Install
```bash
yarn add post-loader --dev
```
## Usage
```js
const postLoader = require('post-loader')
module.exports = {
module: {
rules: [{
test: /\.md$/,
loader: 'post-loader'
}]
}
}
```
## Example
Given `my-blog-post.md`:
```markdown
---
title: hello there
---
post **body**
```
Yields:
```js
{
"data": {
"title": "hello there",
"date": "2017-02-28T14:57:59.000Z"
},
"content": "post **body**",
"html": null
}
```
Which is `require-able` in other files:
```js
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.
## Use a markdown parser
```js
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:
```js
{
"data": {
"title": "hello there",
"date": "2017-02-28T14:57:59.000Z"
},
"content": "post **body**",
"html": "
post options
\\\\n\\"
}
```
## Contributing
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D
## Author
**post-loader** © [egoist](https://github.com/egoist), Released under the [MIT](./LICENSE) License.
Authored and maintained by egoist with help from contributors ([list](https://github.com/egoist/post-loader/contributors)).
> [egoistian.com](https://egoistian.com) · GitHub [@egoist](https://github.com/egoist) · Twitter [@_egoistlily](https://twitter.com/_egoistlily)