mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 22:01:49 +03:00
35e3e0708c
- The proxy is not a helper, we want the helpers folder to only include helpers - The proxy is also meant to be the interface to Ghost for the helpers, and we want to enforce that - This is a small step on the way
40 lines
1.2 KiB
JavaScript
40 lines
1.2 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 {urlService, SafeString, hbs, templates} = require('../services/proxy');
|
|
const buildInHelpers = hbs.handlebars.helpers;
|
|
const _ = require('lodash');
|
|
|
|
/**
|
|
* @deprecated: will be removed in Ghost 3.0
|
|
*/
|
|
module.exports = function author(options) {
|
|
if (options.fn) {
|
|
return buildInHelpers.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);
|
|
};
|