mirror of https://gitlab.com/curben/blog
fix(cssFilter): use renderer
* instead of filter due to conflict with hexo-yam
This commit is contained in:
parent
7dc55833fb
commit
0cc5bbb017
|
@ -4,28 +4,27 @@
|
||||||
/*
|
/*
|
||||||
* Normalize typing.css using sanitize.css
|
* Normalize typing.css using sanitize.css
|
||||||
* Add browser prefixes using autoprefixer
|
* 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 autoprefixer = require('autoprefixer')
|
||||||
|
const micromatch = require('micromatch')
|
||||||
|
const normalize = require('postcss-normalize')
|
||||||
|
const postcss = require('postcss')
|
||||||
|
|
||||||
function cssFilter (str, data) {
|
hexo.extend.renderer.register('css', 'css', (data, options, callback) => {
|
||||||
const path = data.path
|
|
||||||
const exclude = '*.min.css'
|
const exclude = '*.min.css'
|
||||||
|
|
||||||
if (path && exclude && exclude.length) {
|
if (micromatch.isMatch(data.path, exclude, { basename: true })) callback(null, data.text)
|
||||||
if (micromatch.isMatch(path, exclude, { basename: true })) return str
|
|
||||||
}
|
|
||||||
|
|
||||||
const output = postcss([normalize, autoprefixer])
|
postcss([normalize, autoprefixer])
|
||||||
.process(str, {from: path})
|
.process(data.text, { from: data.path })
|
||||||
.then(result => {
|
.then(result => {
|
||||||
return result.css
|
callback(null, result.css)
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
callback(error)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return output
|
|
||||||
}
|
|
||||||
|
|
||||||
hexo.extend.filter.register('after_render:css', cssFilter)
|
|
||||||
|
|
Loading…
Reference in New Issue