0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

🐛 Fixed global and post code injection output (#8824)

no issue

- if a custom post code injection is defined, we output both
This commit is contained in:
Katharina Irrgang 2017-08-02 15:06:51 +04:00 committed by Aileen Nowak
parent 197b6345e6
commit 2f866a99f6
4 changed files with 19 additions and 9 deletions

View file

@ -16,10 +16,12 @@ module.exports = function ghost_foot(options) {
globalCodeinjection = settingsCache.get('ghost_foot'),
postCodeinjection = options.data.root && options.data.root.post ? options.data.root.post.codeinjection_foot : null;
if (!_.isEmpty(globalCodeinjection)) {
foot.push(globalCodeinjection);
}
if (!_.isEmpty(postCodeinjection)) {
foot.push(postCodeinjection);
} else if (!_.isEmpty(globalCodeinjection)) {
foot.push(globalCodeinjection);
}
return filters

View file

@ -156,12 +156,14 @@ module.exports = function ghost_head(options) {
escapeExpression(metaData.rssUrl) + '" />');
// no code injection for amp context!!!
if (!_.includes(context, 'amp') && (!_.isEmpty(globalCodeinjection) || !_.isEmpty(postCodeInjection))) {
if (postCodeInjection) {
head.push(postCodeInjection);
} else {
if (!_.includes(context, 'amp')) {
if (!_.isEmpty(globalCodeinjection)) {
head.push(globalCodeinjection);
}
if (!_.isEmpty(postCodeInjection)) {
head.push(postCodeInjection);
}
}
return filters.doFilter('ghost_head', head);
}).then(function (head) {

View file

@ -43,7 +43,7 @@ describe('{{ghost_foot}} helper', function () {
}
}).then(function (rendered) {
should.exist(rendered);
rendered.string.should.not.match(/<script type="text\/javascript">var test = 'I am a variable!'<\/script>/);
rendered.string.should.match(/<script type="text\/javascript">var test = 'I am a variable!'<\/script>/);
rendered.string.should.match(/post-codeinjection/);
done();

View file

@ -1189,13 +1189,13 @@ describe('{{ghost_head}} helper', function () {
}).catch(done);
});
it('outputs post codeinjection', function (done) {
it('outputs post codeinjection as well', function (done) {
helpers.ghost_head.call(
{safeVersion: '0.3', context: ['paged', 'index']},
{data: {root: {context: [], post: {codeinjection_head: 'post-codeinjection'}}}}
).then(function (rendered) {
should.exist(rendered);
rendered.string.should.not.match(/<style>body {background: red;}<\/style>/);
rendered.string.should.match(/<style>body {background: red;}<\/style>/);
rendered.string.should.match(/post-codeinjection/);
done();
@ -1263,6 +1263,12 @@ describe('{{ghost_head}} helper', function () {
});
describe('with Ajax Helper', function () {
before(function () {
configUtils.set({
url: 'http://localhost:82832/'
});
});
it('renders script tag with src', function (done) {
helpers.ghost_head.call(
{safeVersion: '0.3', context: ['paged', 'index'], post: false},