Skip to content

Commit ce37f00

Browse files
ltoinelLudovic Toinelcathysarisky9larsons
authored
šŸ› Stopped injecting portal when portal.url is set to 'false' in config file (TryGhost#21936)
no ref Co-authored-by: Ludovic Toinel <ltoinel@free.fr> Co-authored-by: Cathy Sarisky <catsarisky@gmail.com> Co-authored-by: Steve Larson <9larsons@gmail.com>
1 parent 3eebfb4 commit ce37f00

2 files changed

Lines changed: 30 additions & 12 deletions

File tree

ā€Žghost/core/core/frontend/helpers/ghost_head.jsā€Ž

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,21 @@ function getMembersHelper(data, frontendKey, excludeList) {
5757
if (!excludeList.has('portal')) {
5858
const {scriptUrl} = getFrontendAppConfig('portal');
5959

60-
const colorString = (_.has(data, 'site._preview') && data.site.accent_color) ? data.site.accent_color : '';
61-
const attributes = {
62-
i18n: true,
63-
ghost: urlUtils.getSiteUrl(),
64-
key: frontendKey,
65-
api: urlUtils.urlFor('api', {type: 'content'}, true),
66-
locale: settingsCache.get('locale') || 'en'
67-
};
68-
if (colorString) {
69-
attributes['accent-color'] = colorString;
60+
if (scriptUrl) {
61+
const colorString = (_.has(data, 'site._preview') && data.site.accent_color) ? data.site.accent_color : '';
62+
const attributes = {
63+
i18n: true,
64+
ghost: urlUtils.getSiteUrl(),
65+
key: frontendKey,
66+
api: urlUtils.urlFor('api', {type: 'content'}, true),
67+
locale: settingsCache.get('locale') || 'en'
68+
};
69+
if (colorString) {
70+
attributes['accent-color'] = colorString;
71+
}
72+
const dataAttributes = getDataAttributes(attributes);
73+
membersHelper += `<script defer src="${scriptUrl}" ${dataAttributes} crossorigin="anonymous"></script>`;
7074
}
71-
const dataAttributes = getDataAttributes(attributes);
72-
membersHelper += `<script defer src="${scriptUrl}" ${dataAttributes} crossorigin="anonymous"></script>`;
7375
}
7476
if (!excludeList.has('cta_styles')) {
7577
membersHelper += (`<style id="gh-members-styles">${templateStyles}</style>`);

ā€Žghost/core/test/unit/frontend/helpers/ghost-head.test.jsā€Ž

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,22 @@ describe('{{ghost_head}} helper', function () {
12711271
}
12721272
}));
12731273
});
1274+
it('does not inject the portal script when portal url is disabled', async function () {
1275+
getStub.withArgs('members_enabled').returns(true);
1276+
getStub.withArgs('paid_members_enabled').returns(true);
1277+
configUtils.set({'portal:url': false});
1278+
1279+
const rendered = (await ghost_head(testUtils.createHbsResponse({
1280+
locals: {
1281+
relativeUrl: '/',
1282+
context: ['home', 'index'],
1283+
safeVersion: '4.3'
1284+
}
1285+
}))).toString();
1286+
1287+
assert.doesNotMatch(rendered, /src="false"/);
1288+
assert.doesNotMatch(rendered, /data-ghost=/);
1289+
});
12741290
});
12751291

12761292
describe('search scripts', function () {

0 commit comments

Comments
Ā (0)