mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Merge pull request #1732 from ErisDS/fix-1730
Date helper fix, moment breaks with null values
This commit is contained in:
commit
1018e9ab79
2 changed files with 22 additions and 3 deletions
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue