From 910dde814f4e6b6f153c0ebb8026cd405eda0737 Mon Sep 17 00:00:00 2001 From: curben <2809763-curben@users.noreply.gitlab.com> Date: Mon, 26 Aug 2019 00:39:10 +0930 Subject: [PATCH] feat: add sanitize.css (via postcss-normalize) and autoprefixer --- package.json | 3 +++ scripts/cssFilter.js | 31 +++++++++++++++++++++++++++++ themes/typing/source/css/typing.css | 1 + 3 files changed, 35 insertions(+) create mode 100644 scripts/cssFilter.js diff --git a/package.json b/package.json index 2b6e933..e6e35cc 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "renovate": "renovate --token $BOT_TOKEN --platform 'gitlab' --onboarding false --update-lock-files false --labels 'renovate' --recreate-closed true --require-config false curben/blog" }, "dependencies": { + "autoprefixer": "^9.6.1", "hexo": "hexojs/hexo", "hexo-generator-archive": "hexojs/hexo-generator-archive", "hexo-generator-tag": "hexojs/hexo-generator-tag", @@ -18,6 +19,8 @@ "hexo-renderer-ejs": "hexojs/hexo-renderer-ejs", "hexo-renderer-marked": "hexojs/hexo-renderer-marked", "hexo-yam": "curbengh/hexo-yam" + "postcss-normalize": "^8.0.1" + "sanitize.css": "^11.0.0" }, "devDependencies": { "hexo-server": "hexojs/hexo-server" diff --git a/scripts/cssFilter.js b/scripts/cssFilter.js new file mode 100644 index 0000000..8cc5a3f --- /dev/null +++ b/scripts/cssFilter.js @@ -0,0 +1,31 @@ +'use strict' +/* global hexo */ + +/* +* Normalize typing.css using sanitize.css +* Add browser prefixes using autoprefixer +*/ + +const micromatch = require('micromatch') +const postcss = require('postcss') +const normalize = require('postcss-normalize') +const autoprefixer = require('autoprefixer') + +function cssFilter (str, data) { + const path = data.path + const exclude = '*.min.css' + + if (path && exclude && exclude.length) { + if (micromatch.isMatch(path, exclude, { basename: true })) return str + } + + const output = postcss([normalize, autoprefixer]) + .process(str, {from: path}) + .then(result => { + return result.css + }) + + return output +} + +hexo.extend.filter.register('after_render:css', cssFilter) diff --git a/themes/typing/source/css/typing.css b/themes/typing/source/css/typing.css index 6845947..6377cc3 100644 --- a/themes/typing/source/css/typing.css +++ b/themes/typing/source/css/typing.css @@ -1,4 +1,5 @@ @charset "utf-8"; +/* Require postcss-normalize */ @import "sanitize"; @import "sanitize/forms"; @import "sanitize/typography";