mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 11:34:24 +03:00
2c6d43a0c0
no issue - Split theme helpers into individual files for each - Do the same for tests - Have utils to share some things between them - Move assetHash onto config
37 lines
1.0 KiB
JavaScript
37 lines
1.0 KiB
JavaScript
// # Date Helper
|
|
// Usage: `{{date format="DD MM, YYYY"}}`, `{{date updated_at format="DD MM, YYYY"}}`
|
|
//
|
|
// Formats a date using moment.js. Formats published_at by default but will also take a date as a parameter
|
|
|
|
var moment = require('moment'),
|
|
date;
|
|
|
|
date = function (context, options) {
|
|
if (!options && context.hasOwnProperty('hash')) {
|
|
options = context;
|
|
context = undefined;
|
|
|
|
// set to published_at by default, if it's available
|
|
// otherwise, this will print the current date
|
|
if (this.published_at) {
|
|
context = this.published_at;
|
|
}
|
|
}
|
|
|
|
// ensure that context is undefined, not null, as that can cause errors
|
|
context = context === null ? undefined : context;
|
|
|
|
var f = options.hash.format || 'MMM Do, YYYY',
|
|
timeago = options.hash.timeago,
|
|
date;
|
|
|
|
if (timeago) {
|
|
date = moment(context).fromNow();
|
|
} else {
|
|
date = moment(context).format(f);
|
|
}
|
|
return date;
|
|
};
|
|
|
|
module.exports = date;
|