post-loader

2.0.0 • Public • Published

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:

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

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

Readme

Keywords

none

Package Sidebar

Install

npm i post-loader

Weekly Downloads

404

Version

2.0.0

License

MIT

Last publish

Collaborators

  • rem