fix(cssFilter): use renderer

* instead of filter due to conflict with hexo-yam
This commit is contained in:
curben 2019-08-26 13:16:47 +09:30
parent 7dc55833fb
commit 0cc5bbb017
No known key found for this signature in database
GPG Key ID: 5D9DB57A25D34EE3
1 changed files with 15 additions and 16 deletions

View File

@ -4,28 +4,27 @@
/*
* Normalize typing.css using sanitize.css
* Add browser prefixes using autoprefixer
*
* renderer is used (instead of filter) due to
* incompatible with hexo-yam
*/
const micromatch = require('micromatch')
const postcss = require('postcss')
const normalize = require('postcss-normalize')
const autoprefixer = require('autoprefixer')
const micromatch = require('micromatch')
const normalize = require('postcss-normalize')
const postcss = require('postcss')
function cssFilter (str, data) {
const path = data.path
hexo.extend.renderer.register('css', 'css', (data, options, callback) => {
const exclude = '*.min.css'
if (path && exclude && exclude.length) {
if (micromatch.isMatch(path, exclude, { basename: true })) return str
}
if (micromatch.isMatch(data.path, exclude, { basename: true })) callback(null, data.text)
const output = postcss([normalize, autoprefixer])
.process(str, {from: path})
postcss([normalize, autoprefixer])
.process(data.text, { from: data.path })
.then(result => {
return result.css
callback(null, result.css)
},
error => {
callback(error)
})
})
return output
}
hexo.extend.filter.register('after_render:css', cssFilter)