0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

🔥 Removed {{author}} helper support

refs https://github.com/TryGhost/Toolbox/issues/230

 - Single {{author}} helper has been deprecated since multiple major releases. It has also been throwing fatal errors in gscan v5 since some time. It will finally be gone!
 - The plural {{authors}} helper should be used instead, read here for more information: https://ghost.org/docs/themes/helpers/authors/
This commit is contained in:
Naz 2022-05-02 17:54:54 +08:00
parent 073b1f8dad
commit 5e441d0942
3 changed files with 1 additions and 93 deletions

View file

@ -1,41 +0,0 @@
// # 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} = require('../services/proxy');
const {SafeString, escapeExpression, hbs, templates} = require('../services/handlebars');
const isString = require('lodash/isString');
const builtInHelpers = hbs.handlebars.helpers;
/**
* @deprecated: single authors was superceded by multiple authors in Ghost 1.22.0
*/
module.exports = function author(options) {
if (options.fn) {
return builtInHelpers.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: escapeExpression(this.author.name)
});
} else {
output = escapeExpression(this.author.name);
}
}
return new SafeString(output);
};

View file

@ -1,51 +0,0 @@
const should = require('should');
const sinon = require('sinon');
const testUtils = require('../../../utils');
const urlService = require('../../../../core/server/services/url');
const authorHelper = require('../../../../core/frontend/helpers/author');
describe('{{author}} helper', function () {
beforeEach(function () {
sinon.stub(urlService, 'getUrlByResourceId');
});
afterEach(function () {
sinon.restore();
});
it('Returns the link to the author from the context', function () {
const author = testUtils.DataGenerator.forKnex.createUser({slug: 'abc123', name: 'abc 123'});
urlService.getUrlByResourceId.withArgs(author.id).returns('author url');
const result = authorHelper.call({author: author}, {hash: {}});
String(result).should.equal('<a href="author url">abc 123</a>');
});
it('Returns the full name of the author from the context if no autolink', function () {
const author = testUtils.DataGenerator.forKnex.createUser({slug: 'abc123', name: 'abc 123'});
const result = authorHelper.call({author: author}, {hash: {autolink: 'false'}});
String(result).should.equal('abc 123');
urlService.getUrlByResourceId.called.should.be.false();
});
it('Returns a blank string where author data is missing', function () {
const result = authorHelper.call({author: null}, {hash: {}});
String(result).should.equal('');
});
it('Functions as block helper if called with #', function () {
const author = testUtils.DataGenerator.forKnex.createUser({slug: 'abc123', name: 'abc 123'});
// including fn emulates the #
const result = authorHelper.call({author: author}, {
hash: {}, fn: function () {
return 'FN';
}
});
// It outputs the result of fn
String(result).should.equal('FN');
urlService.getUrlByResourceId.called.should.be.false();
});
});

View file

@ -8,7 +8,7 @@ const helpers = require('../../../../../../core/frontend/services/helpers');
describe('Helpers', function () {
const hbsHelpers = ['each', 'if', 'unless', 'with', 'helperMissing', 'blockHelperMissing', 'log', 'lookup', 'block', 'contentFor'];
const ghostHelpers = [
'asset', 'author', 'authors', 'body_class', 'cancel_link', 'concat', 'content', 'date', 'encode', 'excerpt', 'facebook_url', 'foreach', 'get',
'asset', 'authors', 'body_class', 'cancel_link', 'concat', 'content', 'date', 'encode', 'excerpt', 'facebook_url', 'foreach', 'get',
'ghost_foot', 'ghost_head', 'has', 'img_url', 'is', 'lang', 'link', 'link_class', 'meta_description', 'meta_title', 'navigation',
'next_post', 'page_url', 'pagination', 'plural', 'post_class', 'prev_post', 'price', 'raw', 'reading_time', 't', 'tags', 'title', 'twitter_url',
'url'