Metalsmith plugin to add metadata on files based on a pattern
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
tests
.gitignore
.jshintrc
.travis.yml
Gruntfile.js
LICENSE
README.md
index.js
package.json

README.md

metalsmith-filemetadata

A Metalsmith plugin to add metadata on files based on a pattern.

Build
Status Dependency
Status

Installation

$ npm install metalsmith-filemetadata

JavaScript usage

var fileMetadata = require('metalsmith-filemetadata');

metalsmith.use(fileMetadata([
    {pattern: "posts/*", metadata: {"section": "blogs", "type": "post"}},
    {pattern: "pages/*", metadata: {"section": "content", "type": "page"}}
]));

The pattern property of each rule should be a valid minimatch pattern. If the pattern matches the file, the corresponding metadata are set on the file entry, For a given file, all patterns are tested, so if several rules are matching, the later can override the previously applied rules.

Adding the preserve: true to any rule will prevent overriding pre-defined values.

CLI usage

{
  "plugins": {
    "metalsmith-filemetadata": [
      {"pattern": "posts/*", "metadata": {"section": "blogs", "type": "post"}},
      {"pattern": "pages/*", "metadata": {"section": "content", "type": "page"}}
    ]
  }
}

License

MIT