A Metalsmith plugin to auto convert dates to moment objects.
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
LICENSE
README.md
index.js
package.json

README.md

Metalsmith Just A Moment

A Metalsmith plugin which automatically converts all dates in files and metadata to moment.js objects.

Explanation

Automatically converting all your date objects to moment.js objects allows you to have very simple access to moment.js formatting inside your templates.

Install

npm install metalsmith-just-a-moment --save

Example

metalsmith.json config example:

{
  "plugins": {
    // These are the default metalsmith-just-a-moment options, shown here only for demonstration.
    "metalsmith-just-a-moment": {
      pattern: ['**/*.md'],
      scanFiles: true,
      scanMetadata: true
    }
  }
}

Build script example:

var metalsmith = require('metalsmith');
var markdown = require('metalsmith-markdown');
var justAMoment = require('metalsmith-just-a-moment');


metalsmith(__dirname)
  .source('src')
  .destination('pub')
  // These are the default metalsmith-just-a-moment options, shown here only for demonstration.
  .use(justAMoment({
    pattern: ['**/*.md'],
    scanFiles: true,
    scanMetadata: true
  }))
  .use(markdown({
    gfm: true,
    tables: true
  }))
  .build(function (err) {
    if (err) {
      throw err;
    }
  });
  

Options

  • pattern
    • Default value: ['**/*.md']
    • Description: Only process files that match this pattern, can be an array of multiple patterns, following multimatch rules.
  • scanFiles
    • Default value: true
    • Description: Should scan files for dates.
  • scanMetadata
    • Default value: true
    • Description: Should scan metadata object for dates.
  • asUTC
    • Default value: false
    • Description: Parse dates as UTC. If your date has a timezone it will be subtracted to get UTC, otherwise your date will be assumed to be UTC.

Caveat

metalsmith-permalinks won't like that your dates are already moment.js objects, if you are using metalsmith-permalinks use metalsmith-just-a-moment after, not before, or use a patched version of metalsmith-permalinks (with other fixes) here.