Skip to content

Latest commit

 

History

History
55 lines (39 loc) · 1.47 KB

README.md

File metadata and controls

55 lines (39 loc) · 1.47 KB

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