Skip to content

hellatan/metalsmith-date-formatter

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 
 
 
 
 
 
 

Metalsmith Date Formatter

Build Status

Format article/post dates based on YAML Front Matter (YFM) data and moment

Installation

npm install --save-dev metalsmith-date-formatter

Usage

Front Matter:

---
publishDate: 2015-05-30
modifedDate: 2015-05-31
---

JavaScript API:

var Metalsmith = require('metalsmith');
var dateFormatter = require('metalsmith-date-formatter');

Metalsmith()
    .use(dateFormatter());

In your template::

<p>published: {{ publishDate }}</p>
<p>last modified: {{ modifiedDate }}</p>

options

dates

This option takes multiple formats

array of objects with key and format properties.

  • The key property is the YFM property name
  • The format property is optional but takes any moment format value
.use(dateFormatter({
    dates: [
        {
            key: 'publishDate',
            format: 'MM DD YYYY'
        },
        {
            key: 'modifiedDate',
            format: 'MM YYYY'
        }
    ]
})

array of strings

.use(dateFormatter({
    dates: ['publishDate', 'modifiedDate']
})

string

.use(dateFormatter({
    dates: 'publishDate'
})

format

Any date format that moment accepts, defaults to MMMM DD, YYYY

Notes

The metalsmith cli workflow has not been tested

About

Format metadata dates

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published