Skip to content

Commit e15ad72

Browse files
authored
fix(#4917): suppress YAMLException when load js-yaml (#4927)
* it is just a workaround
1 parent 8d21027 commit e15ad72

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/plugins/renderer/yaml.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22

33
const yaml = require('js-yaml');
44
const { escape } = require('hexo-front-matter');
5-
const schema = yaml.DEFAULT_SCHEMA.extend(require('js-yaml-js-types').all);
5+
const log = require('hexo-log')();
6+
7+
let schema = {};
8+
// FIXME: workaround for https://github.com/hexojs/hexo/issues/4917
9+
try {
10+
schema = yaml.DEFAULT_SCHEMA.extend(require('js-yaml-js-types').all);
11+
} catch (e) {
12+
if (e instanceof yaml.YAMLException) {
13+
log.warn('YAMLException: please see https://github.com/hexojs/hexo/issues/4917');
14+
} else {
15+
throw e;
16+
}
17+
}
618

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

0 commit comments

Comments
 (0)