Ghost/core/frontend/helpers/author.js
Hannah Wolfe 814a0054e7 Improved single author deprecated notices
- single authors were deprecated in v1.22 when we added multiple authors
- we always thought we'd clean this up a lot sooner, but it's stuck because it's an annoying thing to break people's shit over
- still saying "remove in vX" isn't useful, we need to know how long a feature has been deprecated so we can judge whether it's safe to remove
2021-05-04 17:11:12 +01:00

40 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 {urlService, SafeString, hbs, templates} = require('../services/proxy');
const buildInHelpers = hbs.handlebars.helpers;
const _ = require('lodash');
/**
* @deprecated: single authors was superceded by multiple authors in Ghost 1.22.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);
};