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

Fixed accent color on pages with no context

refs: refs 74fe765410

- 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
This commit is contained in:
Hannah Wolfe 2021-03-04 10:55:51 +00:00
parent 4ac5feaa0a
commit 84e5bdc46a
2 changed files with 27 additions and 1 deletions

View file

@ -178,7 +178,7 @@ module.exports = function ghost_head(options) { // eslint-disable-line camelcase
const styleTag = `<style>:root {--ghost-accent-color: ${accentColor};}</style>`;
const existingScriptIndex = _.findLastIndex(head, str => str.match(/<\/(style|script)>/));
if (existingScriptIndex) {
if (existingScriptIndex !== -1) {
head[existingScriptIndex] = head[existingScriptIndex] + styleTag;
} else {
head.push(styleTag);

View file

@ -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('<style>:root {--ghost-accent-color: #123456;}</style>');
done();
}).catch(done);
});
});
});