1. metalsmith-define
A Metalsmith plugin to define values in the metadata
metalsmith-define
Package: metalsmith-define
Created by: aymericbeaumet
Last modified: Sun, 19 Jun 2022 18:13:13 GMT
Version: 2.1.3
License: MIT
Downloads: 299
Repository: https://github.com/aymericbeaumet/metalsmith-define

Install

npm install metalsmith-define
yarn add metalsmith-define

metalsmith-define

travis
github
npm

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.env to your templates (NODE_ENV, etc)
  • expose JSON files (e.g.: expose the package.json file 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.entries if the method exists (e.g.,
    Map),
  • or
    Object.entries
    for 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.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code