-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Added content_api_key helper (#21151)
no ref This very small helper adds {{content_api_key}} to the collection of handlebars helpers available to theme creators. This will make it easier for themes to access the content API key, without either requiring the user to get it from the integrations page and input it on the theme setting page or resorting to JavaScript to read it from one of the built-in script tag attributes -- both ugly workarounds.
- Loading branch information
1 parent
86d6130
commit d8c4dfe
Showing
3 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const {SafeString} = require('../services/handlebars'); | ||
const logging = require('@tryghost/logging'); | ||
const {getFrontendKey} = require('../services/proxy'); | ||
|
||
module.exports = async function content_api_key() { // eslint-disable-line camelcase | ||
try { | ||
const frontendKey = await getFrontendKey(); | ||
|
||
if (!frontendKey) { | ||
logging.warn('contentkey: No content key found'); | ||
return ''; | ||
} | ||
return new SafeString(frontendKey); | ||
} catch (error) { | ||
logging.error(error); | ||
return ''; | ||
} | ||
}; | ||
module.exports.async = true; |
19 changes: 19 additions & 0 deletions
19
ghost/core/test/unit/frontend/helpers/content_api_key.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* eslint-disable no-regex-spaces */ | ||
const proxy = require('../../../../core/frontend/services/proxy'); | ||
const {getFrontendKey} = proxy; | ||
const should = require('should'); | ||
|
||
// Stuff we are testing | ||
const content_api_key = require('../../../../core/frontend/helpers/content_api_key'); | ||
|
||
describe('{{content_api_key}} helper', function () { | ||
describe('compare to settings', function () { | ||
it('returns the content API key', async function () { | ||
const result = await content_api_key(); | ||
const expected = await getFrontendKey(); | ||
should.exist(result); | ||
String(result).should.equal(expected); | ||
}); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters