From c8ab73be293652ce4ec4f107471f005323cfa8de Mon Sep 17 00:00:00 2001 From: Cathy Sarisky Date: Fri, 27 Sep 2024 20:39:57 -0400 Subject: [PATCH 1/3] content_api_key helper --- .../core/frontend/helpers/content_api_key.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 ghost/core/core/frontend/helpers/content_api_key.js diff --git a/ghost/core/core/frontend/helpers/content_api_key.js b/ghost/core/core/frontend/helpers/content_api_key.js new file mode 100644 index 00000000000..5101fa043f0 --- /dev/null +++ b/ghost/core/core/frontend/helpers/content_api_key.js @@ -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; \ No newline at end of file From e51debfd000cbbb744762e55a7cbf15b7108600a Mon Sep 17 00:00:00 2001 From: Cathy Sarisky Date: Fri, 27 Sep 2024 21:02:28 -0400 Subject: [PATCH 2/3] fix test :) --- .../frontend/services/theme-engine/handlebars/helpers.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ghost/core/test/unit/frontend/services/theme-engine/handlebars/helpers.test.js b/ghost/core/test/unit/frontend/services/theme-engine/handlebars/helpers.test.js index 5cb6dc1d800..d0d7be1019c 100644 --- a/ghost/core/test/unit/frontend/services/theme-engine/handlebars/helpers.test.js +++ b/ghost/core/test/unit/frontend/services/theme-engine/handlebars/helpers.test.js @@ -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' From 52af9749c602192ece2dd8d1380df5431fe08c9a Mon Sep 17 00:00:00 2001 From: Cathy Sarisky Date: Tue, 1 Oct 2024 09:22:20 -0400 Subject: [PATCH 3/3] test for content_api_key added, passing. --- .../frontend/helpers/content_api_key.test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 ghost/core/test/unit/frontend/helpers/content_api_key.test.js diff --git a/ghost/core/test/unit/frontend/helpers/content_api_key.test.js b/ghost/core/test/unit/frontend/helpers/content_api_key.test.js new file mode 100644 index 00000000000..cc4862c7fcb --- /dev/null +++ b/ghost/core/test/unit/frontend/helpers/content_api_key.test.js @@ -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); + }); + }); +}); +