diff --git a/ghost/admin/initializers/ghost-config.js b/ghost/admin/initializers/ghost-config.js index 519d900306..244f14fe7a 100644 --- a/ghost/admin/initializers/ghost-config.js +++ b/ghost/admin/initializers/ghost-config.js @@ -1,16 +1,11 @@ +import getConfig from 'ghost/utils/config-parser'; + var ConfigInitializer = { name: 'config', initialize: function (container, application) { - var apps = $('body').data('apps'), - tagsUI = $('body').data('tagsui'), - fileStorage = $('body').data('filestorage'), - blogUrl = $('body').data('blogurl'), - blogTitle = $('body').data('blogtitle'); - - application.register( - 'ghost:config', {apps: apps, fileStorage: fileStorage, blogUrl: blogUrl, tagsUI: tagsUI, blogTitle: blogTitle}, {instantiate: false} - ); + var config = getConfig(); + application.register('ghost:config', config, {instantiate: false}); application.inject('route', 'config', 'ghost:config'); application.inject('controller', 'config', 'ghost:config'); diff --git a/ghost/admin/utils/config-parser.js b/ghost/admin/utils/config-parser.js new file mode 100644 index 0000000000..7082fa04f9 --- /dev/null +++ b/ghost/admin/utils/config-parser.js @@ -0,0 +1,36 @@ +var isNumeric = function (num) { + return !isNaN(num); + }, + + _mapType = function (val) { + if (val === '') { + return null; + } else if (val === 'true') { + return true; + } else if (val === 'false') { + return false; + } else if (isNumeric(val)) { + return +val; + } else { + return val; + } + }, + + parseConfiguration = function () { + var metaConfigTags = $('meta[name^="env-"]'), + propertyName, + config = {}, + value, + key, + i; + + for (i = 0; i < metaConfigTags.length; i += 1) { + key = $(metaConfigTags[i]).prop('name'); + value = $(metaConfigTags[i]).prop('content'); + propertyName = key.substring(4); // produce config name ignoring the initial 'env-'. + config[propertyName] = _mapType(value); // map string values to types if possible + } + return config; + }; + +export default parseConfiguration;