0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-15 03:01:37 -05:00

🗑Deprecated ghost_head & ghost_foot in favour of codeinjection_* for Settings API v2 (#10380)

closes #10373

- ghost_head & ghost_foot are deprecated from now on
- we want to remove them in v3
- this short fix is dirty (!)
- we return codeinjection_* for admin & content api
- this is a consistentency change e.g. posts return `post.codeinjection_*`
- need to raise a decoupling refactoring issue for the code comments
This commit is contained in:
Katharina Irrgang 2019-01-15 13:03:17 +01:00 committed by GitHub
parent cf1e4aa593
commit 3924acd152
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 0 deletions

View file

@ -6,6 +6,8 @@ module.exports = {
browse: {
permissions: true,
query() {
// @TODO: decouple settings cache from API knowledge
// The controller fetches models (or cached models) and the API frame for the target API version formats the response.
return settingsCache.getPublic();
}
}

View file

@ -11,3 +11,28 @@ module.exports.forPost = (frame, model, attrs) => {
}
}
};
// @NOTE: ghost_head & ghost_foot are deprecated, remove in Ghost 3.0
module.exports.forSettings = (attrs) => {
const _ = require('lodash');
// @TODO: https://github.com/TryGhost/Ghost/issues/10106
// @NOTE: Admin & Content API return a different format, need to mappers
if (_.isArray(attrs)) {
const ghostHead = _.cloneDeep(_.find(attrs, {key: 'ghost_head'}));
const ghostFoot = _.cloneDeep(_.find(attrs, {key: 'ghost_foot'}));
if (ghostHead) {
ghostHead.key = 'codeinjection_head';
attrs.push(ghostHead);
}
if (ghostFoot) {
ghostFoot.key = 'codeinjection_foot';
attrs.push(ghostFoot);
}
} else {
attrs.codeinjection_head = attrs.ghost_head;
attrs.codeinjection_foot = attrs.ghost_foot;
}
};

View file

@ -72,6 +72,7 @@ const mapPost = (model, frame) => {
const mapSettings = (attrs) => {
url.forSettings(attrs);
extraAttrs.forSettings(attrs);
return attrs;
};

View file

@ -45,6 +45,7 @@ themeMiddleware.ensureActiveTheme = function ensureActiveTheme(req, res, next) {
themeMiddleware.updateTemplateData = function updateTemplateData(req, res, next) {
// Static information, same for every request unless the settings change
// @TODO: bind this once and then update based on events?
// @TODO: decouple theme layer from settings cache using the Content API
var siteData = settingsCache.getPublic(),
labsData = _.cloneDeep(settingsCache.get('labs')),
themeData = {};

View file

@ -46,6 +46,19 @@ describe('Settings', function () {
// Verify that we are returning the defaults for each value
_.forEach(settings, (value, key) => {
/**
* @TODO:
* This test is coupled with the settings cache and the model schema.
* This test should compare against the API result using the test utility.
* The settings cache should only cache model responses and should not know about
* API or theme formats.
*
* This is just a hack to be able to alias ghost_head & ghost_foot quickly.
*/
if (['codeinjection_head', 'codeinjection_foot'].includes(key)) {
return;
}
let defaultKey = _.findKey(publicSettings, (v) => v === key);
let defaultValue = _.find(defaultSettings, (setting) => setting.key === defaultKey).defaultValue;