1.2.2 • Published 5 years ago

hoast-frontmatter v1.2.2

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

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 a content and frontmatter property both of type string.
    • Type: Function
    • Required: no
  • 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 or Array of strings Default: `[ '.md' ]`
  • patternOptions: Options for the glob pattern matching. See planckmatch options for more details on the pattern options.
    • Type: Object
    • Default: {}
  • patternOptions.all: This options is added to patternOptions, and determines whether all patterns need to match instead of only one.
    • Type: Boolean
    • Default: false

Examples

CLI

{
  "modules": {
    "read": {},
    "hoast-frontmatter": {}
  }
}

Script

const Hoast = require(`hoast`);
const read = Hoast.read,
      frontmatter = require(`hoast-frontmatter`);

Hoast(__dirname)
  .use(read())
  .use(frontmatter())
  .process();

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 = require(`hoast`);
const read = Hoast.read,
      frontmatter = require(`hoast-frontmatter`);
const matter = require(`gray-matter`);

Hoast(__dirname)
  .use(read())
  .use(frontmatter({
    engine: function(filePath, content) {
      const result = matter(content, {
        excerpt: true
      });
      
      return {
        content: result.content,
        frontmatter: Object.assign({ excerpt: result.excerpt }, result.data)
      };
    }
  }))
  .process();

Extract the YAML frontmatter and an excerpt from any .md files using gray-matter.

1.2.2

5 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.1.0-alpha.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

1.0.0-beta.2

6 years ago

1.0.0-beta.1

6 years ago

1.0.0-beta.0

6 years ago

0.1.0

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago

0.0.0

6 years ago