From 1cc3f3504352b4cf7fc8d994747a7710f3c2851e Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 3 Mar 2021 08:00:41 +0000 Subject: [PATCH] Fixed accent color not updating in front-end preview refs https://github.com/TryGhost/Ghost/pull/12717 - preview data is set on `options.data.site` so we need to read from that rather than directly from the settings cache --- core/frontend/helpers/ghost_head.js | 4 ++-- test/unit/helpers/ghost_head_spec.js | 27 +++++++++++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/core/frontend/helpers/ghost_head.js b/core/frontend/helpers/ghost_head.js index bdff4146e4..c95eb5191a 100644 --- a/core/frontend/helpers/ghost_head.js +++ b/core/frontend/helpers/ghost_head.js @@ -173,8 +173,8 @@ module.exports = function ghost_head(options) { // eslint-disable-line camelcase } } - if (settingsCache.get('accent_color')) { - const accentColor = escapeExpression(settingsCache.get('accent_color')); + if (options.data.site.accent_color) { + const accentColor = escapeExpression(options.data.site.accent_color); const styleTag = ``; const existingScriptIndex = _.findLastIndex(head, str => str.match(/<\/(style|script)>/)); diff --git a/test/unit/helpers/ghost_head_spec.js b/test/unit/helpers/ghost_head_spec.js index b72b15c684..467570c29e 100644 --- a/test/unit/helpers/ghost_head_spec.js +++ b/test/unit/helpers/ghost_head_spec.js @@ -1555,13 +1555,18 @@ describe('{{ghost_head}} helper', function () { describe('accent_color', function () { it('includes style tag when set', function (done) { - settingsCache.get.withArgs('accent_color').returns('#123456'); - const renderObject = { post: posts[1] }; + const templateOptions = { + site: { + accent_color: '#123456' + } + }; + helpers.ghost_head(testUtils.createHbsResponse({ + templateOptions, renderObject: renderObject, locals: { relativeUrl: '/post/', @@ -1576,13 +1581,18 @@ describe('{{ghost_head}} helper', function () { }); it('does not include style tag when not set', function (done) { - settingsCache.get.withArgs('accent_color').returns(null); - const renderObject = { post: posts[1] }; + const templateOptions = { + site: { + accent_color: null + } + }; + helpers.ghost_head(testUtils.createHbsResponse({ + templateOptions, renderObject: renderObject, locals: { relativeUrl: '/post/', @@ -1597,13 +1607,18 @@ describe('{{ghost_head}} helper', function () { }); it('attaches style tag to existing script/style tag', function (done) { - settingsCache.get.withArgs('accent_color').returns('#123456'); - const renderObject = { post: posts[1] }; + const templateOptions = { + site: { + accent_color: '#123456' + } + }; + helpers.ghost_head(testUtils.createHbsResponse({ + templateOptions, renderObject: renderObject, locals: { relativeUrl: '/post/',