From 0cc5bbb0173103eb30734675dd6a5cf84691c662 Mon Sep 17 00:00:00 2001 From: curben <2809763-curben@users.noreply.gitlab.com> Date: Mon, 26 Aug 2019 13:16:47 +0930 Subject: [PATCH] fix(cssFilter): use renderer * instead of filter due to conflict with hexo-yam --- scripts/cssFilter.js | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/scripts/cssFilter.js b/scripts/cssFilter.js index 8cc5a3f..38dc3e5 100644 --- a/scripts/cssFilter.js +++ b/scripts/cssFilter.js @@ -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) +})