mirror of https://gitlab.com/curben/blog
refactor(cssFilter): promise-fy
This commit is contained in:
parent
0dee19bfdf
commit
03e82cfb2c
|
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
postcss([normalize, autoprefixer])
|
postcss([normalize, autoprefixer])
|
||||||
.process(data.text, { from: data.path })
|
.process(data.text, { from: data.path })
|
||||||
.then(result => {
|
.then(result => {
|
||||||
callback(null, result.css)
|
resolve(result.css)
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
callback(error)
|
reject(error)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue