Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨Add content_api_key helper #21151

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ghost/core/core/frontend/helpers/content_api_key.js
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 ghost/core/test/unit/frontend/helpers/content_api_key.test.js
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);
});
});
});

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const helpers = require('../../../../../../core/frontend/services/helpers');
describe('Helpers', function () {
const hbsHelpers = ['each', 'if', 'unless', 'with', 'helperMissing', 'blockHelperMissing', 'log', 'lookup', 'block', 'contentFor'];
const ghostHelpers = [
'asset', 'authors', 'body_class', 'cancel_link', 'concat', 'content', 'date', 'encode', 'excerpt', 'facebook_url', 'foreach', 'get',
'asset', 'authors', 'body_class', 'cancel_link', 'concat', 'content', 'content_api_key', 'date', 'encode', 'excerpt', 'facebook_url', 'foreach', 'get',
'ghost_foot', 'ghost_head', 'has', 'img_url', 'is', 'link', 'link_class', 'meta_description', 'meta_title', 'navigation',
'next_post', 'page_url', 'pagination', 'plural', 'post_class', 'prev_post', 'price', 'raw', 'reading_time', 't', 'tags', 'title','total_members', 'total_paid_members', 'twitter_url',
'url', 'comment_count', 'collection', 'recommendations', 'readable_url'
Expand Down
Loading