Skip to content

Commit

Permalink
fix(hexojs#4917): suppress YAMLException when load js-yaml (hexojs#4927)
Browse files Browse the repository at this point in the history
* it is just a workaround
  • Loading branch information
yoshinorin committed Apr 4, 2022
1 parent 0b5cc8a commit d17926c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/plugins/renderer/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@

const yaml = require('js-yaml');
const { escape } = require('hexo-front-matter');
const schema = yaml.DEFAULT_SCHEMA.extend(require('js-yaml-js-types').all);
const log = require('hexo-log')();

let schema = {};
// FIXME: workaround for https://github.com/hexojs/hexo/issues/4917
try {
schema = yaml.DEFAULT_SCHEMA.extend(require('js-yaml-js-types').all);
} catch (e) {
if (e instanceof yaml.YAMLException) {
log.warn('YAMLException: please see https://github.com/hexojs/hexo/issues/4917');
} else {
throw e;
}
}

function yamlHelper(data) {
return yaml.load(escape(data.text), { schema });
Expand Down

0 comments on commit d17926c

Please sign in to comment.