refactor(cssFilter): promise-fy

This commit is contained in:
curben 2019-08-26 13:48:10 +09:30
parent 0dee19bfdf
commit 03e82cfb2c
No known key found for this signature in database
GPG Key ID: 5D9DB57A25D34EE3
1 changed files with 14 additions and 10 deletions

View File

@ -14,17 +14,21 @@ const micromatch = require('micromatch')
const normalize = require('postcss-normalize') const normalize = require('postcss-normalize')
const postcss = require('postcss') 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' 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]) return new Promise((resolve, reject) => {
.process(data.text, { from: data.path }) postcss([normalize, autoprefixer])
.then(result => { .process(data.text, { from: data.path })
callback(null, result.css) .then(result => {
}, resolve(result.css)
error => { },
callback(error) error => {
}) reject(error)
})
})
}) })