Skip to content

Webpack loader to extract frontmatter using jxson/front-matter

License

Notifications You must be signed in to change notification settings

elliottsj/front-matter-loader

Repository files navigation

front-matter-loader

npm version

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

About

Webpack loader to extract frontmatter using jxson/front-matter

Resources

License

Stars

Watchers

Forks

Packages

No packages published