mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 01:03:23 +03:00
243b387063
refs #8126, #8221, #8223 ✨ New 'Proxy' for all helper requires - this is not currently enforced, but could be, much like apps - the proxy object is HUGE - changed date to use SafeString, this should have been there anyway - use the proxy for all helpers, including those in apps 😁 ✨ 🎨 Single instance of hbs for theme + for errors - we now have theme/engine instead of requiring express-hbs everywhere - only error-handler still also requires express-hbs, this is so that we can render errors without extra crud - TODO: remove the asset helper after #8126 IF it is not needed, or else remove the TODO 🎨 Cleanup visibility utils 🎨 Clean up the proxy a little bit 🚨 Unskip test as it now works! 🎨 Minor amends as per comments
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
// # Date Helper
|
|
// Usage: `{{date format="DD MM, YYYY"}}`, `{{date updated_at format="DD MM, YYYY"}}`
|
|
//
|
|
// Formats a date using moment-timezone.js. Formats published_at by default but will also take a date as a parameter
|
|
|
|
var proxy = require('./proxy'),
|
|
moment = require('moment-timezone'),
|
|
SafeString = proxy.SafeString;
|
|
|
|
module.exports = function (date, options) {
|
|
var timezone, format, timeago, timeNow;
|
|
|
|
if (!options && date.hasOwnProperty('hash')) {
|
|
options = date;
|
|
date = undefined;
|
|
timezone = options.data.blog.timezone;
|
|
|
|
// set to published_at by default, if it's available
|
|
// otherwise, this will print the current date
|
|
if (this.published_at) {
|
|
date = moment(this.published_at).tz(timezone).format();
|
|
}
|
|
}
|
|
|
|
// ensure that context is undefined, not null, as that can cause errors
|
|
date = date === null ? undefined : date;
|
|
|
|
format = options.hash.format || 'MMM DD, YYYY';
|
|
timeago = options.hash.timeago;
|
|
timeNow = moment().tz(timezone);
|
|
|
|
if (timeago) {
|
|
date = timezone ? moment(date).tz(timezone).from(timeNow) : moment(date).fromNow();
|
|
} else {
|
|
date = timezone ? moment(date).tz(timezone).format(format) : moment(date).format(format);
|
|
}
|
|
|
|
return new SafeString(date);
|
|
};
|