Webpack loader to extract frontmatter using jxson/front-matter
JavaScript
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
.eslintignore
.eslintrc
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
index.js
index.test.js
package.json
yarn.lock

README.md

front-matter-loader

npm version Greenkeeper badge

Webpack loader to extract frontmatter using jxson/front-matter

Installation

npm install front-matter-loader

Usage

Given a file with frontmatter, e.g. example.md:

---
title: Example
description: This is an example
---

Here is some example content

The frontmatter can be extracted like this (using json-loader):

var exampleFrontmatter = require('json-loader!front-matter-loader!./example.md')

console.log(exampleFrontmatter.attributes.title)
// => 'Example'
console.log(exampleFrontmatter.attributes.description)
// => 'This is an example'
console.log(exampleFrontmatter.body)
// => 'Here is some example content'

To extract only the frontmatter attributes of the target file, use the onlyAttributes query parameter:

var exampleAttributes = require('json-loader!front-matter-loader?onlyAttributes!./example.md')
console.log(exampleAttributes.title)
// => 'Example'
console.log(exampleAttributes.description)
// => 'This is an example'

To extract only the body content of the target file, use the onlyBody query parameter:

var exampleContent = require('raw-loader!front-matter-loader?onlyBody!./example.md')

For a complete example using a webpack config, see example/.