Ghost/core/server/data/meta/context_object.js
Katharina Irrgang 0201c431d7 🔥 do not store settings in config (#7924)
* 🎨  🔥  do not store settings in config and make settings cache easier available

- remove remembering settings value in theme config
- if we need a cache value, we are asking the settings cache directly
- instead of settings.getSettingSync we use settings.cache.get

- added TODO:
  - think about moving the settings cache out of api/settings
  - we could create a folder named cache cache/settings
  - this settings cache listens on model changes for settings
  - decoupling

* 🔥  remove timezone from config

- no need to store in overrides config and in defaults settings

* 🎨  context object helper

- replace config.get('theme') by settings cache

* 🎨  replace config.get('theme') by settings.cache.get

* 🎨  adapt tests

* fixes from comments
2017-02-03 13:15:11 +00:00

21 lines
642 B
JavaScript

var settingsCache = require('../../api/settings').cache,
_ = require('lodash');
function getContextObject(data, context) {
/**
* If the data object does not contain the requested context, we return the fallback object.
*/
var blog = {
cover: settingsCache.get('cover'),
twitter: settingsCache.get('twitter'),
facebook: settingsCache.get('facebook')
},
contextObject;
context = _.includes(context, 'page') || _.includes(context, 'amp') ? 'post' : context;
contextObject = data[context] || blog;
return contextObject;
}
module.exports = getContextObject;