From 03e82cfb2c7b3c8f659ccf7bcd3cc3accce85bae Mon Sep 17 00:00:00 2001 From: curben <2809763-curben@users.noreply.gitlab.com> Date: Mon, 26 Aug 2019 13:48:10 +0930 Subject: [PATCH] refactor(cssFilter): promise-fy --- scripts/cssFilter.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/scripts/cssFilter.js b/scripts/cssFilter.js index 38dc3e5..49f1a53 100644 --- a/scripts/cssFilter.js +++ b/scripts/cssFilter.js @@ -14,17 +14,21 @@ const micromatch = require('micromatch') const normalize = require('postcss-normalize') const postcss = require('postcss') -hexo.extend.renderer.register('css', 'css', (data, options, callback) => { +hexo.extend.renderer.register('css', 'css', (data, options) => { const exclude = '*.min.css' - if (micromatch.isMatch(data.path, exclude, { basename: true })) callback(null, data.text) + if (data.path) { + if (micromatch.isMatch(data.path, exclude, { basename: true })) return data.text + } - postcss([normalize, autoprefixer]) - .process(data.text, { from: data.path }) - .then(result => { - callback(null, result.css) - }, - error => { - callback(error) - }) + return new Promise((resolve, reject) => { + postcss([normalize, autoprefixer]) + .process(data.text, { from: data.path }) + .then(result => { + resolve(result.css) + }, + error => { + reject(error) + }) + }) })