mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 02:11:44 +03:00
40064a395a
- we export i18n from `core/frontend/services/proxy` and this is used in the most of the places in the frontend code - this commit aligns the rest of the code in core/frontend to use the proxy too - unfortunately core/frontend/services/themes/i18n.js loops back to the proxy so we have a circular dependency
32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
const yaml = require('js-yaml');
|
|
const debug = require('ghost-ignition').debug('frontend:services:settings:yaml-parser');
|
|
const {i18n} = require('../proxy');
|
|
const errors = require('@tryghost/errors');
|
|
|
|
/**
|
|
* Takes a YAML file, parses it and returns a JSON Object
|
|
* @param {YAML} file the YAML file utf8 encoded
|
|
* @param {String} fileName the name of the file incl. extension
|
|
* @returns {Object} parsed
|
|
*/
|
|
module.exports = function parseYaml(file, fileName) {
|
|
try {
|
|
const parsed = yaml.safeLoad(file);
|
|
|
|
debug('YAML settings file parsed:', fileName);
|
|
|
|
return parsed;
|
|
} catch (error) {
|
|
// CASE: parsing failed, `js-yaml` tells us exactly what and where in the
|
|
// `reason` property as well as in the message.
|
|
// As the file uploaded is invalid, the person uploading must fix this - it's a 4xx error
|
|
throw new errors.IncorrectUsageError({
|
|
message: i18n.t('errors.services.settings.yaml.error', {file: fileName, context: error.reason}),
|
|
code: 'YAML_PARSER_ERROR',
|
|
context: error.message,
|
|
err: error,
|
|
help: i18n.t('errors.services.settings.yaml.help', {file: fileName})
|
|
});
|
|
}
|
|
};
|