wasm-frontmatter
extracts the frontmatter data from markdown.
$ npm install --save wasm-frontmatter
const {matter} = require('wasm-frontmatter');
const long_markdown = `---
title: "long form content"
description: "Front matter"
categories:
- "test"
- "categories"
---
This is content`;
results = matter(long_markdown);
console.log(results.data.title);
Type: Boolean
Default: false
Extracts an excerpt that directly follows front-matter, or is the first thing in the string if no front-matter exists.
If set to excerpt: true
, it will look for the frontmatter delimiter, ---
and grab everything leading up to it.
Example
const str = '---\nfoo: bar\n---\nThis is an excerpt.\n---\nThis is content';
const file = matter(str, { excerpt: true });
Results in:
{
content: 'This is an excerpt.\n---\nThis is content',
data: { foo: 'bar' },
excerpt: 'This is an excerpt.\n'
}
Type: String
Default: ---
Allows for a custom separator to use for excerpts.
Example
const str = '---\nfoo: bar\n---\nThis is an excerpt.\n<!-- end -->\nThis is content';
console.log(matter(str, {excerpt_separator: '<!-- end -->'}));
Results in:
{
content: 'This is an excerpt.\n<!-- end -->\nThis is content',
data: { foo: 'bar' },
excerpt: 'This is an excerpt.\n'
}
Type: String
Default: ---
Allows for a custom delimiter to define the frontmatter.
Example:
const str = '~~~\nfoo: bar\n~~~\nThis is content';
console.log(matter(str, {delimiter: '~~~'}));
Results in:
{
content: 'This is content',
data: { foo: 'bar' },
excerpt: ''
}
Modify src/lib.rs
and run make build
to update the package. Can run tests using the included index.js
file. Or write tests and run make test
.
This package is built using Rust, wasm_bindgen, and wasm-pack. Hoping this finds itself to be fast since it's using wasm, but I don't know. This is very much experimental.