refactor(cssFilter): async/await

This commit is contained in:
curben 2019-09-25 00:10:57 +01:00
parent be57b4edab
commit 996cb83aa2
No known key found for this signature in database
GPG Key ID: 5D9DB57A25D34EE3
1 changed files with 3 additions and 11 deletions

View File

@ -13,19 +13,11 @@ const autoprefixer = require('autoprefixer')
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) => { hexo.extend.renderer.register('css', 'css', async (data) => {
if (data.path) { if (data.path) {
if (data.path.endsWith('.min.css')) return data.text if (data.path.endsWith('.min.css')) return data.text
} }
return new Promise((resolve, reject) => { const result = await postcss([normalize, autoprefixer]).process(data.text, { from: data.path })
postcss([normalize, autoprefixer]) return result.css
.process(data.text, { from: data.path })
.then(result => {
resolve(result.css)
},
error => {
reject(error)
})
})
}) })