2014-10-10 18:54:07 +04:00
|
|
|
// # 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
|
|
|
|
|
2017-04-04 19:07:35 +03:00
|
|
|
var proxy = require('./proxy'),
|
|
|
|
_ = require('lodash'),
|
|
|
|
SafeString = proxy.SafeString,
|
|
|
|
handlebars = proxy.hbs.handlebars,
|
|
|
|
templates = proxy.templates,
|
|
|
|
url = proxy.url;
|
2014-10-10 18:54:07 +04:00
|
|
|
|
2018-03-27 17:16:15 +03:00
|
|
|
/**
|
|
|
|
* @deprecated: will be removed in Ghost 2.0
|
|
|
|
*/
|
2017-04-04 19:07:35 +03:00
|
|
|
module.exports = function author(options) {
|
2014-10-10 18:54:07 +04:00
|
|
|
if (options.fn) {
|
2017-04-04 19:07:35 +03:00
|
|
|
return handlebars.helpers.with.call(this, this.author, options);
|
2014-10-10 18:54:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
var autolink = _.isString(options.hash.autolink) && options.hash.autolink === 'false' ? false : true,
|
|
|
|
output = '';
|
|
|
|
|
|
|
|
if (this.author && this.author.name) {
|
|
|
|
if (autolink) {
|
2017-04-04 19:07:35 +03:00
|
|
|
output = templates.link({
|
|
|
|
url: url.urlFor('author', {author: this.author}),
|
2014-10-10 18:54:07 +04:00
|
|
|
text: _.escape(this.author.name)
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
output = _.escape(this.author.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-04 19:07:35 +03:00
|
|
|
return new SafeString(output);
|
2014-10-10 18:54:07 +04:00
|
|
|
};
|