hoast-frontmatter
Extracts frontmatter from files. By default it only extracts JSON
at the top of a file, but can easily be extended using the engine option.
As the name suggest this is a hoast module.
Usage
Install hoast-frontmatter using npm.
$ npm install --save hoast-frontmatter
Parameters
engine
: Function to overwrite default frontmatter extraction. Function should accept two arguments the file path and content both of type string. The return should be an object with acontent
andfrontmatter
property both of type string.- Type:
Function
- Required:
no
- Type:
patterns
: Glob patterns to match file paths with. If the engine function is set it will only give the function any files matching the pattern.- Type:
String
orArray of strings
- Default:
[ '*.md' ]
- Default:
- Type:
patternOptions
: Options for the glob pattern matching. See planckmatch options for more details on the pattern options.- Type:
Object
- Default:
{}
- Type:
patternOptions.all
: This options is added topatternOptions
, and determines whether all patterns need to match instead of only one.- Type:
Boolean
- Default:
false
- Type:
Examples
CLI
Script
const Hoast = ;const read = Hoastread frontmatter = ; ;
By default it will extract the JSON frontmatter from any
.md
files.
CLI
engine
option is not compatible with the CLI tool as it requires a reference to a self specified function.
Script
const Hoast = ;const read = Hoastread frontmatter = ;const matter = ; ;
Extract the
YAML
frontmatter and an excerpt from any.md
files using gray-matter.