Use Gray-matter
Import gray-matter
const matter = require('gray-matter');Pass a string to gray-matter.
console.log(matter('---\ntitle: Front Matter\n---\nThis is content.'));Returns:
{
content: '\nThis is content.',
data: {
title: 'Front Matter'
}
}Example.
Create file file.html with the following content.
---
title: Hello
slug: home
---
<h1>Hello world!</h1>Create file example.js with the following content.
Run in the terminal
As a result an object like this.
Reference Links
Last updated