Skip to content

Webpack loader for blog posts written in Markdown.

License

Notifications You must be signed in to change notification settings

egoist/post-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Webpack loader for blog posts written in Markdown.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published