mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
10fc320cc8
no issue - In Ghost, 'context' means the page or section of a blog we're currently within when rendering a theme, e.g. 'post' or 'tag' or 'home'. - In handlebars 'context' refers to the blob of JSON that is tied to a template. - These two uses of the word 'context' have gotten very confusing, so I've removed all usage of 'context' within the Ghost handlebars helpers, EXCEPT where they actually refer to the current context (e.g. the is helper)
36 lines
981 B
JavaScript
36 lines
981 B
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 (date, options) {
|
|
if (!options && date.hasOwnProperty('hash')) {
|
|
options = date;
|
|
date = undefined;
|
|
|
|
// set to published_at by default, if it's available
|
|
// otherwise, this will print the current date
|
|
if (this.published_at) {
|
|
date = this.published_at;
|
|
}
|
|
}
|
|
|
|
// ensure that context is undefined, not null, as that can cause errors
|
|
date = date === null ? undefined : date;
|
|
|
|
var f = options.hash.format || 'MMM Do, YYYY',
|
|
timeago = options.hash.timeago;
|
|
|
|
if (timeago) {
|
|
date = moment(date).fromNow();
|
|
} else {
|
|
date = moment(date).format(f);
|
|
}
|
|
return date;
|
|
};
|
|
|
|
module.exports = date;
|