2019-08-25 15:09:10 +00:00
|
|
|
'use strict'
|
|
|
|
/* global hexo */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Normalize typing.css using sanitize.css
|
|
|
|
* Add browser prefixes using autoprefixer
|
2019-08-26 03:46:47 +00:00
|
|
|
*
|
|
|
|
* renderer is used (instead of filter) due to
|
|
|
|
* incompatible with hexo-yam
|
2019-08-25 15:09:10 +00:00
|
|
|
*/
|
|
|
|
|
2019-08-26 03:46:47 +00:00
|
|
|
const autoprefixer = require('autoprefixer')
|
2019-08-25 15:09:10 +00:00
|
|
|
const normalize = require('postcss-normalize')
|
2019-08-26 03:46:47 +00:00
|
|
|
const postcss = require('postcss')
|
2019-08-25 15:09:10 +00:00
|
|
|
|
2019-08-26 04:18:10 +00:00
|
|
|
hexo.extend.renderer.register('css', 'css', (data, options) => {
|
|
|
|
if (data.path) {
|
2019-08-26 04:25:45 +00:00
|
|
|
if (data.path.endsWith('.min.css')) return data.text
|
2019-08-26 04:18:10 +00:00
|
|
|
}
|
2019-08-25 15:09:10 +00:00
|
|
|
|
2019-08-26 04:18:10 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
postcss([normalize, autoprefixer])
|
|
|
|
.process(data.text, { from: data.path })
|
|
|
|
.then(result => {
|
|
|
|
resolve(result.css)
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
reject(error)
|
|
|
|
})
|
|
|
|
})
|
2019-08-26 03:46:47 +00:00
|
|
|
})
|