metalsmith-filemetadata

4.0.0 • Public • Published

metalsmith-filemetadata

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

Build status

Installation

This plugin requires Node.js 18 or later

$ npm install metalsmith-filemetadata

JavaScript usage

const 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

Readme

Keywords

Package Sidebar

Install

npm i metalsmith-filemetadata

Weekly Downloads

63

Version

4.0.0

License

MIT

Unpacked Size

9.24 kB

Total Files

9

Last publish

Collaborators

  • dpobel