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 = ;var markdown = ;var justAMoment = ; source'src' // These are the default metalsmith-just-a-moment options, shown here only for demonstration. ;
Options
pattern
- Default value:
['**/*.md']
- Description: Only process files that match this pattern, can be an array of multiple patterns, following multimatch rules.
- Default value:
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.