Now with Partition Management

    @metalsmith/default-values

    3.2.0 • Public • Published

    @metalsmith/default-values

    A Metalsmith plugin for setting default values to file metadata.

    metalsmith: core plugin npm: version ci: build code coverage license: GPL-3.0

    Installation

    NPM:

    npm install @metalsmith/default-values

    Yarn:

    yarn add @metalsmith/default-values

    Usage:

    Pass @metalsmith/default-values to metalsmith.use:

    const default_values = require('@metalsmith/default-values')
    
    metalsmith.use(
      default_values([
        {
          pattern: 'posts/*.md',
          defaults: {
            layout: 'post.hbs',
            date: function (post) {
              return post.stats.ctime
            }
          }
        },
        {
          pattern: 'diary/*.md',
          defaults: {
            layout: 'diary.hbs',
            private: true
          }
        },
        {
          pattern: ['diary/*.md', 'archive/**/*.md'],
          defaults: {
            no_index: true
          }
        },
        {
          pattern: '**/*.md',
          defaults: {
            layout: 'default.hbs'
          }
        }
      ])
    )

    Options

    @metalsmith/default-values takes an array of objects which specify the defaults to set for all files matching a pattern. The objects have the following properties:

    • pattern (string|string[]): One or more glob patterns to match file paths
    • defaults (Object<string, any>): An object whose key-value pairs will be added to file metadata. You can also specify a function callback(file) to set dynamic defaults based on other, existing file metadata.

    Debug

    To enable debug logs, set the DEBUG environment variable to @metalsmith/default-values:

    Linux/Mac:

    DEBUG=@metalsmith/default-values
    

    Windows:

    set "DEBUG=@metalsmith/default-values"
    

    Alternatively you can set DEBUG to @metalsmith/* to debug all Metalsmith core plugins.

    CLI usage

    To use this plugin with the Metalsmith CLI, add @metalsmith/default-values to the plugins key in your metalsmith.json file:

    {
      "plugins": [
        {
          "@metalsmith/default-values": [
            {
              "pattern": "diary/*.md",
              "defaults": {
                "layout": "diary.hbs",
                "private": true
              }
            }
          ]
        }
      ]
    }

    License

    GPL-3.0

    Install

    npm i @metalsmith/default-values

    DownloadsWeekly Downloads

    4

    Version

    3.2.0

    License

    GPL-3.0

    Unpacked Size

    52.1 kB

    Total Files

    6

    Last publish

    Collaborators

    • webketje
    • ismay
    • woodyrew