From 5e441d0942e263427db9b267c5140d04e484339f Mon Sep 17 00:00:00 2001 From: Naz Date: Mon, 2 May 2022 17:54:54 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Removed=20{{author}}=20helper=20?= =?UTF-8?q?support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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/ --- core/frontend/helpers/author.js | 41 --------------- test/unit/frontend/helpers/author.test.js | 51 ------------------- .../theme-engine/handlebars/helpers.test.js | 2 +- 3 files changed, 1 insertion(+), 93 deletions(-) delete mode 100644 core/frontend/helpers/author.js delete mode 100644 test/unit/frontend/helpers/author.test.js diff --git a/core/frontend/helpers/author.js b/core/frontend/helpers/author.js deleted file mode 100644 index b27bab4cf1..0000000000 --- a/core/frontend/helpers/author.js +++ /dev/null @@ -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); -}; diff --git a/test/unit/frontend/helpers/author.test.js b/test/unit/frontend/helpers/author.test.js deleted file mode 100644 index 2822a7bf2d..0000000000 --- a/test/unit/frontend/helpers/author.test.js +++ /dev/null @@ -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('abc 123'); - }); - - 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(); - }); -}); diff --git a/test/unit/frontend/services/theme-engine/handlebars/helpers.test.js b/test/unit/frontend/services/theme-engine/handlebars/helpers.test.js index ba0e8c13fe..2a9956dc1d 100644 --- a/test/unit/frontend/services/theme-engine/handlebars/helpers.test.js +++ b/test/unit/frontend/services/theme-engine/handlebars/helpers.test.js @@ -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'