Skip to content

Commit

Permalink
perf(render): avoid using new Promise
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Sep 22, 2021
1 parent f277e09 commit 188279f
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/hexo/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,19 @@ class Render {
const ctx = this.context;
let ext = '';

return new Promise((resolve, reject) => {
if (!data) return reject(new TypeError('No input file or string!'));
if (data.text != null) return resolve(data.text);
if (!data.path) return reject(new TypeError('No input file or string!'));
let promise;

readFile(data.path).then(resolve, reject);
}).then(text => {
if (!data) return Promise.reject(new TypeError('No input file or string!'));

if (data.text != null) {
promise = Promise.resolve(data.text);
} else if (!data.path) {
return Promise.reject(new TypeError('No input file or string!'));
} else {
promise = readFile(data.path);
}

return promise.then(text => {
data.text = text;
ext = data.engine || getExtname(data.path);
if (!ext || !this.isRenderable(ext)) return text;
Expand Down

0 comments on commit 188279f

Please sign in to comment.