From 6ba1eafb469d7b85207ff14ae22fcaa82ee8b15e Mon Sep 17 00:00:00 2001 From: jerryoung Date: Sat, 5 Feb 2022 12:51:39 +0800 Subject: [PATCH 1/2] fix: update hexo 5.x after, it use yml.js 4.x .After yml.js 4.x load method replace safeLoad method, safeDump method as well. --- api.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/api.js b/api.js index 511b37f5..cfb1ea09 100644 --- a/api.js +++ b/api.js @@ -41,8 +41,12 @@ module.exports = function (app, hexo) { fs.writeFile(hexo.base_dir+'_admin-config.yml', '') return {} } else { - var settings = yml.safeLoad(fs.readFileSync(path)) - + // Update hexo 5.x after, it used yml.js 4.x .After yml.js 4.x "load" method replace "safeLoad" method. + if (hexo.version[0] < '5') { + var settings = yml.safeLoad(fs.readFileSync(path)) + } else { + var settings = yml.load(fs.readFileSync(path)) + } if (!settings) return {} return settings } @@ -184,8 +188,12 @@ module.exports = function (app, hexo) { settings = deepAssign(settings, addedOptions) } hexo.log.d('set', name, '=', value, 'with', JSON.stringify(addedOptions)) - - fs.writeFileSync(hexo.base_dir + '_admin-config.yml', yml.safeDump(settings)) + // Update hexo 5.x after, it used yml.js 4.x .After yml.js 4.x "dump" method replace "safeDump" method. + if (hexo.version[0] < '5') { + fs.writeFileSync(hexo.base_dir + '_admin-config.yml', yml.safeDump(settings)) + } else { + fs.writeFileSync(hexo.base_dir + '_admin-config.yml', yml.dump(settings)) + } res.done({ updated: 'Successfully updated ' + name + ' = ' + value, settings: settings From 31fbe15c14f10bb0d052f6757b5e61ad6ddfc52d Mon Sep 17 00:00:00 2001 From: jaryoung Date: Sat, 5 Feb 2022 12:57:14 +0800 Subject: [PATCH 2/2] update style update code indent --- api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api.js b/api.js index cfb1ea09..98671e9a 100644 --- a/api.js +++ b/api.js @@ -41,7 +41,7 @@ module.exports = function (app, hexo) { fs.writeFile(hexo.base_dir+'_admin-config.yml', '') return {} } else { - // Update hexo 5.x after, it used yml.js 4.x .After yml.js 4.x "load" method replace "safeLoad" method. + // Update hexo 5.x after, it used yml.js 4.x .After yml.js 4.x "load" method replace "safeLoad" method. if (hexo.version[0] < '5') { var settings = yml.safeLoad(fs.readFileSync(path)) } else {