Netherworld's Pretend Minibar
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

metalsmith-each

0.1.1 • Public • Published

metalsmith-each

A Metalsmith plugin for easily applying a function to each file or filename.

This offers a simpler API than creating a full metalsmith plugin for the common case of iterating over each file individually and doing something to the file or filename.

Installation

$ npm install metalsmith-each

Usage

Just pass a function to metalsmith-each that accepts the metalsmith file object and, optionally, the filename.

var each = require('metalsmith-each');
 
metalsmith.use(
  each(function (file, filename) {
    file.build_date = new Date();
  }
));
 

To change the filename, just return a string with the new name.

var each = require('metalsmith-each');
 
metalsmith.use(
  each(function (file, filename) {
    return filename.toUpperCase();
  }
));

Functions can be async, too. Just accept a done() function as the third argument. Note: If you accept the done function, you must call it or your build will hang.

var each = require('metalsmith-each');
 
metalsmith.use(
  each(function (file, filename, done) {
    setTimeout(function () {
      file.build_date = new Date();
      done();
    }, 1000);
  }
));

To rename a file with an async function, pass the new name to the done() function.

var each = require('metalsmith-each');
 
metalsmith.use(
  each(function (file, filename, done) {
    setTimeout(function () {
      done(filename.toUpperCase());
    }, 1000);
  }
));

License

MIT

install

npm i metalsmith-each

Downloadsweekly downloads

9

version

0.1.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability