Ghost/core/server/helpers/author.js
Katharina Irrgang 7b0d5d465b 🐛 Fixed preview url and Zapier on subdirectory (#9683)
closes #9675

- with dynamic routing we have introduced a breaking change, which we have overseen
- Ghost does not return absolute urls, that's why the clients need to concat the blog url and the resource url
- with 1.24.0 Ghost returned resource urls including the subdirectory
- this caused trouble for e.g. zapier or the preview feature in the admin client
- revert breaking change and ensure we only expose resource urls without subdirectory
2018-06-12 16:36:58 +01:00

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 2.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);
};