From 6ddd284d9637237b34181e2fd6e673f0117f7005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E8=BF=9B=E7=A6=84?= Date: Tue, 8 Mar 2022 15:07:12 +0800 Subject: [PATCH] gulpfile --- gulpfile.js | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 gulpfile.js diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..78d3f9b --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,66 @@ +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: /