yaml-fm
About | Installation | API | Usage | License
About
yaml-fm
is a Node.js module that converts a String with YAML frontmatter to an Object.
It uses currying to be .map()
friendly and converts non-YAML content to a trimmed Buffer.
Use it to build your own personal static-site generator!
Turn this:
---title: Hello worldslug: post/hello_world/index.htmltags: - excellent - adventure--- Hello world!
Into this:
title: 'Hello world' slug: 'post/hello_world/index.html' tags: 'excellent' 'adventure' content: <Buffer 48 65 6c 6c 6f 20 77 6f 72 6c 64 21>
Installation
Install
$ npm install --save yaml-fm
Require
var fm =
API
yaml-fm(delim)
delim
: string: required delimiter before and after YAML frontmatter
Returns an anonymous function.
fn(string)
string
: string: string to parse containing YAML frontmatter
Returns a flat JS object.
Non-frontmatter is trimmed, converted to a Buffer, and included in Object.content
.
Usage
.map()
Without // require modulevar fm = // delimiter for YAMLvar delim = '---' // string containing YAML frontmattervar stringWithFm = `---title: Hello worldslug: post/hello_world/index.htmltags: - excellent - adventure--- Hello world!` // parse string// NOTE: because fm is curried, it must be called twicevar fmObj = stringWithFm /** fmObj: { title: 'Hello world', slug: 'post/hello_world/index.html', tags: ['excellent', 'adventure'], content: <Buffer 48 65 6c 6c 6f 20 77 6f 72 6c 64 21> } */
.map()
With See example.
// modulesvar fm = var fs = var globby = var bb = // promisify fs.readFilevar bbpath 'utf8' // glob -> paths -> strings -> objects /** NOTE: The fm transform could also look like this: .then(strs => strs.map(str => fm('---')(str))) Because yaml-fm uses currying, we can shorten that to the code seen above: .then(strs => strs.map(fm('---'))) */