front-matter-loader

2.0.0 • Public • Published

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

/front-matter-loader/

    Package Sidebar

    Install

    npm i front-matter-loader

    Weekly Downloads

    212

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    5.66 kB

    Total Files

    12

    Last publish

    Collaborators

    • elliottsj