feat: add sanitize.css (via postcss-normalize) and autoprefixer

This commit is contained in:
curben 2019-08-26 00:39:10 +09:30
parent 31d99f0dab
commit 910dde814f
No known key found for this signature in database
GPG Key ID: 5D9DB57A25D34EE3
3 changed files with 35 additions and 0 deletions

View File

@ -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"

31
scripts/cssFilter.js Normal file
View File

@ -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)

View File

@ -1,4 +1,5 @@
@charset "utf-8";
/* Require postcss-normalize */
@import "sanitize";
@import "sanitize/forms";
@import "sanitize/typography";