0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-15 03:01:37 -05:00

Fallbacks and defaults for {{date}} helper

closes #608

If no context is specified, falls back to using published_at
If published_at is not available, will output today's date
This commit is contained in:
Hannah Wolfe 2013-09-02 20:12:45 +01:00
parent be62a550f9
commit 53063366e0

View file

@ -20,9 +20,22 @@ coreHelpers = function (ghost) {
* @return {Object} A Moment time / date object
*/
ghost.registerThemeHelper('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;
}
}
var f = options.hash.format || "MMM Do, YYYY",
timeago = options.hash.timeago,
date;
if (timeago) {
date = moment(context).fromNow();
} else {