metalsmith-define

2019-10-23

A Metalsmith plugin to define values in the metadata

metalsmith-define

travisgithubnpm

This plugin enables you to define custom values in the metadata. Why you would use it for is up to you, but here are some ideas:

  • expose a node module (e.g.: Lodash) in the metadata to use it in a template
  • expose process.envto your templates (NODE_ENV, etc)
  • expose JSON files (e.g.: expose the package.jsonfile similarly to how it's done in a classic Gruntfile)
  • expose your own JavaScript modules (e.g., define custom helper functions)

Install

npm install metalsmith-define

Usage

CLI

metalsmith.json

{
  "plugins": {
    "metalsmith-define": {
      "production": true
    }
  }
}

Node.js

const metalsmith = require('metalsmith')
const metalsmithDefine = require('metalsmith-define')

metalsmith(__dirname).use(
  metalsmithDefine({
    _: require('underscore'),
    development: true,
    pkg: require('./package.json'),
    helpers: require('./helpers.js'),
  })
)

API

metalsmithDefine(options)

options

Type: Enumerable(Array, Class, Map, Object, string, etc)Default: {}

This parameter will be iterated on all its key/value pairs either via:

  • {type}.prototype.entriesif the method exists (e.g., Map),
  • or Object.entriesfor all the other types: Array, Object, etc

The pairs will be merged into the metadata object in the order in which they are being iterated on.

HomePage

https://github.com/aymericbeaumet/metalsmith-define

Repository

https://github.com/aymericbeaumet/metalsmith-define.git


上一篇:metalsmith-markdownit
下一篇:metalsmith-debug
相关教程
关注微信

扫码加入 JavaScript 社区

相关文章

首次访问,需要验证
微信扫码,关注即可
(仅需验证一次)

欢迎加入 JavaScript 社区

号内回复关键字:

回到顶部