mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
✨ Added accent color CSS variable to {{ghost_head}}
(#12717)
closes https://github.com/TryGhost/Team/issues/508 - if an accent colour is set in site settings, output a `--accent-color` CSS variable in a `<style>` tag through `{{ghost_head}}` - allows themes to use the accent colour without adding an additional conditional with CSS variable declaration to their default template
This commit is contained in:
parent
886f564dc4
commit
74fe765410
@ -173,6 +173,18 @@ module.exports = function ghost_head(options) { // eslint-disable-line camelcase
|
||||
}
|
||||
}
|
||||
|
||||
if (settingsCache.get('accent_color')) {
|
||||
const accentColor = escapeExpression(settingsCache.get('accent_color'));
|
||||
const styleTag = `<style>:root {--accent-color: ${accentColor};}</style>`;
|
||||
const existingScriptIndex = _.findLastIndex(head, str => str.match(/<\/(style|script)>/));
|
||||
|
||||
if (existingScriptIndex) {
|
||||
head[existingScriptIndex] = head[existingScriptIndex] + styleTag;
|
||||
} else {
|
||||
head.push(styleTag);
|
||||
}
|
||||
}
|
||||
|
||||
head.push('<meta name="generator" content="Ghost ' +
|
||||
escapeExpression(safeVersion) + '" />');
|
||||
|
||||
|
@ -1552,4 +1552,69 @@ describe('{{ghost_head}} helper', function () {
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('accent_color', function () {
|
||||
it('includes style tag when set', function (done) {
|
||||
settingsCache.get.withArgs('accent_color').returns('#123456');
|
||||
|
||||
const renderObject = {
|
||||
post: posts[1]
|
||||
};
|
||||
|
||||
helpers.ghost_head(testUtils.createHbsResponse({
|
||||
renderObject: renderObject,
|
||||
locals: {
|
||||
relativeUrl: '/post/',
|
||||
context: ['post'],
|
||||
safeVersion: '0.3'
|
||||
}
|
||||
})).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.containEql('<style>:root {--accent-color: #123456;}</style>');
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('does not include style tag when not set', function (done) {
|
||||
settingsCache.get.withArgs('accent_color').returns(null);
|
||||
|
||||
const renderObject = {
|
||||
post: posts[1]
|
||||
};
|
||||
|
||||
helpers.ghost_head(testUtils.createHbsResponse({
|
||||
renderObject: renderObject,
|
||||
locals: {
|
||||
relativeUrl: '/post/',
|
||||
context: ['post'],
|
||||
safeVersion: '0.3'
|
||||
}
|
||||
})).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.not.containEql('--accent-color');
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('attaches style tag to existing script/style tag', function (done) {
|
||||
settingsCache.get.withArgs('accent_color').returns('#123456');
|
||||
|
||||
const renderObject = {
|
||||
post: posts[1]
|
||||
};
|
||||
|
||||
helpers.ghost_head(testUtils.createHbsResponse({
|
||||
renderObject: renderObject,
|
||||
locals: {
|
||||
relativeUrl: '/post/',
|
||||
context: ['post'],
|
||||
safeVersion: '0.3'
|
||||
}
|
||||
})).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.match(/[^\s]<style>:root/);
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user