mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-04 04:10:33 +03:00
9c38d1a2d3
fixes #1730
33 lines
922 B
JavaScript
33 lines
922 B
JavaScript
/*globals Handlebars, moment
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
Handlebars.registerHelper('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;
|
|
});
|
|
}());
|