Ghost/ghost/admin/utils/config-parser.js
Nazar Gargol b35aecc712 Cleans up HTML data attributes on body in default.hbs
closes #4485

- removes data attributes used on body in default.hbs
- introduces new way to generate configuration through meta tags
- config initializer consumes configurations from the meta tags using parser
- moves blog_title helper/value to be a property in a configuration api
2014-11-29 17:09:43 +01:00

37 lines
1.0 KiB
JavaScript

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;