mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 12:53:13 +03:00
1142561532
closes #5294 This improves a hack for parsing JSON to be more robust. Now attempt to parse JSON, and if it's not possible it will fallback to treating the value is a string, reverting the behaviour to what it would have been if we didn't have JSON parsing here.
44 lines
1.2 KiB
JavaScript
44 lines
1.2 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 if (val.indexOf('{') === 0) {
|
|
try {
|
|
return JSON.parse(val);
|
|
} catch (e) {
|
|
/*jshint unused:false */
|
|
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;
|