const gulp = require('gulp'),
htmlmin = require('gulp-html-minifier-terser'), // html压缩组件
htmlclean = require('gulp-htmlclean'), // html清理组件
plumber = require('gulp-plumber'), // 容错组件(发生错误不跳出任务,并报出错误内容)
Hexo = require('hexo'),
log = require('fancy-log') // gulp的日志输出
// 程序执行的传参
const argv = require('minimist')(process.argv.slice(2))
const hexo = new Hexo(process.cwd(), {})
// 创建静态页面 (等同 hexo generate)
gulp.task('generate', async function() {
try {
await hexo.init()
await hexo.call('clean')
await hexo.call('generate', { watch: false })
return hexo.exit()
} catch (err) {
await hexo.exit(err)
throw err // 让 gulp series 感知到失败并终止后续任务
}
})
// 压缩public目录下的html文件
gulp.task('compressHtml', () => {
const cleanOptions = {
protect: /<\!--%fooTemplate\b.*?%-->/g, //忽略处理
unprotect: /