front-matter-loader
v2.0.0
Published
Webpack loader to extract frontmatter using jxson/front-matter
Downloads
1,634
Maintainers
Readme
front-matter-loader
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/.