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:
parent
be62a550f9
commit
53063366e0
1 changed files with 13 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue