metalsmith-filemetadata
Metalsmith plugin to add metadata on files based on a pattern
Last updated 2 months ago by dpobel .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install metalsmith-filemetadata 
SYNC missed versions from official npm registry.

metalsmith-filemetadata

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

BuildStatus

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 latter can override the previously applied rules.

The metadata property can also be a function, to enable making global metadata available to files, or setting file metadata defaults, e.g.:

{
  pattern: "posts/*",
  metadata: function(file, globalMetadata) {
    return {
      title: file.keywords || globalMetadata.keywords,
      allPosts: globalMetadata.collections.posts
    };
  }
}

Adding 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

Current Tags

  • 0.0.3                                ...           0.0.3 (6 years ago)
  • 2.1.0                                ...           latest (2 months ago)
  • 0.0.2                                ...           v0.0.2 (6 years ago)

7 Versions

  • 2.1.0                                ...           2 months ago
  • 2.0.0                                ...           3 months ago
  • 1.0.0                                ...           5 years ago
  • 0.0.4                                ...           6 years ago
  • 0.0.3                                ...           6 years ago
  • 0.0.2                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 2
Dependencies (1)
Dev Dependencies (2)

Copyright 2014 - 2016 © taobao.org |