diff --git a/core/client/helpers/index.js b/core/client/helpers/index.js index cacaf9c7a6..b44239fe54 100644 --- a/core/client/helpers/index.js +++ b/core/client/helpers/index.js @@ -2,10 +2,26 @@ */ (function () { 'use strict'; - Handlebars.registerHelper('date', function (context, block) { - var f = block.hash.format || 'MMM Do, YYYY', - timeago = block.hash.timeago, + 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 { diff --git a/core/server/helpers/index.js b/core/server/helpers/index.js index 975ae4d99e..c958376d0c 100644 --- a/core/server/helpers/index.js +++ b/core/server/helpers/index.js @@ -39,6 +39,9 @@ coreHelpers.date = function (context, options) { } } + // 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;