From 84e5bdc46a8d28328aae95bb7c08144094f79d82 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Thu, 4 Mar 2021 10:55:51 +0000 Subject: [PATCH] Fixed accent color on pages with no context refs: refs https://github.com/TryGhost/Ghost/commit/74fe765410a2997e685f4f2c56eadf7a35df7440 - Some pages, like error pages have no context. - In that case there is also no previous style or script tag and so the existingScriptIndex is -1, not 0/falsy :D - This ensures we always add this style tag --- core/frontend/helpers/ghost_head.js | 2 +- test/unit/helpers/ghost_head_spec.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/core/frontend/helpers/ghost_head.js b/core/frontend/helpers/ghost_head.js index c95eb5191a..70029a3313 100644 --- a/core/frontend/helpers/ghost_head.js +++ b/core/frontend/helpers/ghost_head.js @@ -178,7 +178,7 @@ module.exports = function ghost_head(options) { // eslint-disable-line camelcase const styleTag = ``; const existingScriptIndex = _.findLastIndex(head, str => str.match(/<\/(style|script)>/)); - if (existingScriptIndex) { + if (existingScriptIndex !== -1) { head[existingScriptIndex] = head[existingScriptIndex] + styleTag; } else { head.push(styleTag); diff --git a/test/unit/helpers/ghost_head_spec.js b/test/unit/helpers/ghost_head_spec.js index 467570c29e..4eb7244b38 100644 --- a/test/unit/helpers/ghost_head_spec.js +++ b/test/unit/helpers/ghost_head_spec.js @@ -1631,5 +1631,31 @@ describe('{{ghost_head}} helper', function () { done(); }).catch(done); }); + + it('includes style tag on templates with no context', function (done) { + const renderObject = { + post: posts[1] + }; + + const templateOptions = { + site: { + accent_color: '#123456' + } + }; + + helpers.ghost_head(testUtils.createHbsResponse({ + templateOptions, + renderObject: renderObject, + locals: { + relativeUrl: '/post/amp/', + context: null, + safeVersion: '0.3' + } + })).then(function (rendered) { + should.exist(rendered); + rendered.string.should.containEql(''); + done(); + }).catch(done); + }); }); });