mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-14 09:52:09 +03:00
a8e987ec6c
fixes #1659, fixes #1668 - removed relative asset url from css - added asset helper to client - updated references to shared assets - added functional tests
54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
/*globals Handlebars, moment, Ghost */
|
|
(function () {
|
|
'use strict';
|
|
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 {
|
|
date = moment(context).format(f);
|
|
}
|
|
return date;
|
|
});
|
|
|
|
Handlebars.registerHelper('url', function () {
|
|
return Ghost.paths.subdir;
|
|
});
|
|
|
|
Handlebars.registerHelper('asset', function (context, options) {
|
|
var output = '',
|
|
isAdmin = options && options.hash && options.hash.ghost;
|
|
|
|
output += Ghost.paths.subdir + '/';
|
|
|
|
if (!context.match(/^shared/)) {
|
|
if (isAdmin) {
|
|
output += 'ghost/';
|
|
} else {
|
|
output += 'assets/';
|
|
}
|
|
}
|
|
|
|
output += context;
|
|
return new Handlebars.SafeString(output);
|
|
});
|
|
}());
|