mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-25 02:31:59 -05:00
Added sodoSearch script output from ghost_head helper
no issue - The sodoSearch needs to be injected into rendered HTML the same way portal scripts are. - The feature is behind a `sodoSearch` alpha flag, so the scripts are injected conditionally
This commit is contained in:
parent
3edbb364fe
commit
f6b2a83761
3 changed files with 36 additions and 2 deletions
|
@ -57,6 +57,16 @@ function getMembersHelper(data, frontendKey) {
|
|||
return membersHelper;
|
||||
}
|
||||
|
||||
function getSearchHelper(frontendKey) {
|
||||
if (!labs.isSet('sodoSearch')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
let helper = `<script defer src="${config.get('sodoSearch:url')}" data-ghost="${urlUtils.getSiteUrl()}" data-key="${frontendKey}" data-api="${urlUtils.urlFor('api', {type: 'content'}, true)}" crossorigin="anonymous"></script>`;
|
||||
|
||||
return helper;
|
||||
}
|
||||
|
||||
/**
|
||||
* **NOTE**
|
||||
* Express adds `_locals`, see https://github.com/expressjs/express/blob/4.15.4/lib/response.js#L962.
|
||||
|
@ -193,6 +203,7 @@ module.exports = async function ghost_head(options) { // eslint-disable-line cam
|
|||
// no code injection for amp context!!!
|
||||
if (!_.includes(context, 'amp')) {
|
||||
head.push(getMembersHelper(options.data, frontendKey));
|
||||
head.push(getSearchHelper(frontendKey));
|
||||
|
||||
// @TODO do this in a more "frameworky" way
|
||||
if (cardAssetService.hasFile('js')) {
|
||||
|
|
|
@ -131,6 +131,9 @@
|
|||
"url": "https://unpkg.com/@tryghost/portal@~2.2.0/umd/portal.min.js",
|
||||
"version": "2.2"
|
||||
},
|
||||
"sodoSearch": {
|
||||
"url": "https://unpkg.com/@tryghost/sodo-search@~0.1.0/umd/sodo-search.min.js"
|
||||
},
|
||||
"tenor": {
|
||||
"publicReadOnlyApiKey": null,
|
||||
"contentFilter": "off"
|
||||
|
|
|
@ -14,7 +14,7 @@ const urlService = require('../../../../core/server/services/url');
|
|||
|
||||
const ghost_head = require('../../../../core/frontend/helpers/ghost_head');
|
||||
const proxy = require('../../../../core/frontend/services/proxy');
|
||||
const {settingsCache} = proxy;
|
||||
const {settingsCache, labs} = proxy;
|
||||
|
||||
describe('{{ghost_head}} helper', function () {
|
||||
let posts = [];
|
||||
|
@ -1578,7 +1578,7 @@ describe('{{ghost_head}} helper', function () {
|
|||
|
||||
it('attaches style tag to existing script/style tag', function (done) {
|
||||
settingsCache.get.withArgs('members_enabled').returns(true);
|
||||
|
||||
|
||||
const renderObject = {
|
||||
post: posts[1]
|
||||
};
|
||||
|
@ -1736,4 +1736,24 @@ describe('{{ghost_head}} helper', function () {
|
|||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('search scripts', function () {
|
||||
it('includes search when labs flag enabled', function (done) {
|
||||
labsStub = sinon.stub(labs, 'isSet').returns(true);
|
||||
|
||||
ghost_head(testUtils.createHbsResponse({
|
||||
locals: {
|
||||
relativeUrl: '/',
|
||||
context: ['home', 'index'],
|
||||
safeVersion: '4.3'
|
||||
}
|
||||
})).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.containEql('<script defer src="https://unpkg.com/@tryghost/sodo-search');
|
||||
rendered.string.should.containEql('data-ghost="http://127.0.0.1:2369/" data-key="xyz" data-api="http://127.0.0.1:2369/ghost/api/content/"');
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue