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 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)
})
})
})