Ghost/ghost/admin/app/utils/config-parser.js
Matt Enlow e50a1157fa Add post preview via uuid (/p/:uuid)
Refs #5097

- All drafts will show a preview link (this needs real css)
- Published posts will redirect
- prev/next post helpers only activate on published posts
- Powered by ~10 pints between the two of us (@ErisDS, @novaugust)
2015-04-30 11:57:37 +01:00

39 lines
1.1 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) {
return JSON.parse(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;