examples

Let's say our page, foo.html contains

---
title: YAML Front matter
description: This is a page
---
<h1>{{title}}</h1>

then running the following in the command line:

console.log(matter('foo.html'));

returns

{
  "data": {
    "title": "YAML Front matter",
    "description": "This is a page"
  },
  "content": "<h1>{{title}}</h1>",
  "original": "---\ntitle: YAML Front matter\n---\n<h1>{{title}}</h1>"
}

and

console.log(matter('foo.html').data);

returns

{"title": "YAML Front matter", "description": "This is a page"}

.extend

Given this page:

---
title: Gray Matter
---
Hooray!

and this config:

var file = require('fs').readFileSync('file.md', 'utf8');
var obj = {
  description: 'A simple to use front matter lib';
};
matter.extend(file, obj);

the result would be:

---
title: Gray Matter
description: A simple to use front matter lib
---
Hooray!

Last updated