post-loader

Webpack loader for blog posts written in Markdown.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
post-loader
422.0.05 years ago6 years agoMinified + gzip package size for post-loader in KB

Readme

post-loader
NPM version NPM downloads Build Status codecov donate

Install

yarn add post-loader --dev

Usage

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:
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

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\\"
}

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, Released under the MIT License.
Authored and maintained by egoist with help from contributors (list).
egoistian.com · GitHub @egoist · Twitter @egoistlily