mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
df7e64fafa
refs #10790 - Moved /core/apps into core/frontend - Moved /core/server/helpers to /core/frontend/helpers along with /core/server/services/themes - Changed helper location in overrides - Moved /core/server/services/routing to /core/frontend/services - Moved /core/server/services/url to /core/frontend/services - Moved /core/server/data/meta to /core/frontend/meta - Moved /core/server/services/rss to /core/frontend/services - Moved /core/server/data/xml to /core/frontend/services
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
// # Author Helper
|
|
// Usage: `{{author}}` OR `{{#author}}{{/author}}`
|
|
//
|
|
// Can be used as either an output or a block helper
|
|
//
|
|
// Output helper: `{{author}}`
|
|
// Returns the full name of the author of a given post, or a blank string
|
|
// if the author could not be determined.
|
|
//
|
|
// Block helper: `{{#author}}{{/author}}`
|
|
// This is the default handlebars behaviour of dropping into the author object scope
|
|
const proxy = require('./proxy'),
|
|
_ = require('lodash'),
|
|
urlService = require('../services/url'),
|
|
SafeString = proxy.SafeString,
|
|
handlebars = proxy.hbs.handlebars,
|
|
templates = proxy.templates;
|
|
|
|
/**
|
|
* @deprecated: will be removed in Ghost 3.0
|
|
*/
|
|
module.exports = function author(options) {
|
|
if (options.fn) {
|
|
return handlebars.helpers.with.call(this, this.author, options);
|
|
}
|
|
|
|
const autolink = _.isString(options.hash.autolink) && options.hash.autolink === 'false' ? false : true;
|
|
let output = '';
|
|
|
|
if (this.author && this.author.name) {
|
|
if (autolink) {
|
|
output = templates.link({
|
|
url: urlService.getUrlByResourceId(this.author.id, {withSubdirectory: true}),
|
|
text: _.escape(this.author.name)
|
|
});
|
|
} else {
|
|
output = _.escape(this.author.name);
|
|
}
|
|
}
|
|
|
|
return new SafeString(output);
|
|
};
|