mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -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:
parent
4ac5feaa0a
commit
84e5bdc46a
2 changed files with 27 additions and 1 deletions
|
@ -178,7 +178,7 @@ module.exports = function ghost_head(options) { // eslint-disable-line camelcase
|
||||||
const styleTag = `<style>:root {--ghost-accent-color: ${accentColor};}</style>`;
|
const styleTag = `<style>:root {--ghost-accent-color: ${accentColor};}</style>`;
|
||||||
const existingScriptIndex = _.findLastIndex(head, str => str.match(/<\/(style|script)>/));
|
const existingScriptIndex = _.findLastIndex(head, str => str.match(/<\/(style|script)>/));
|
||||||
|
|
||||||
if (existingScriptIndex) {
|
if (existingScriptIndex !== -1) {
|
||||||
head[existingScriptIndex] = head[existingScriptIndex] + styleTag;
|
head[existingScriptIndex] = head[existingScriptIndex] + styleTag;
|
||||||
} else {
|
} else {
|
||||||
head.push(styleTag);
|
head.push(styleTag);
|
||||||
|
|
|
@ -1631,5 +1631,31 @@ describe('{{ghost_head}} helper', function () {
|
||||||
done();
|
done();
|
||||||
}).catch(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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue