const gulp = require('gulp'),
htmlmin = require('gulp-htmlmin'), // html压缩组件
htmlclean = require('gulp-htmlclean'), // html清理组件
plumber = require('gulp-plumber'), // 容错组件(发生错误不跳出任务,并报出错误内容)
Hexo = require('hexo'),
log = require('fancy-log') // gulp的日志输出
// 程序执行的传参
const argv = require('optimist')
// .demand(['accessKey', 'accessSecret', 'deployPath'])
.describe('accessKey', '网易云对象存储key')
.describe('accessSecret', '网易云对象存储secret')
.describe('deployPath', '静态化后发布的目录')
.argv
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) {
return hexo.exit(err)
}
})
// 压缩public目录下的html文件
gulp.task('compressHtml', () => {
const cleanOptions = {
protect: /<\!--%fooTemplate\b.*?%-->/g, //忽略处理
unprotect: /