diff --git a/.gitignore b/.gitignore index d4babe9..1964dfb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,12 @@ .DS_Store Thumbs.db db.json +package-lock.json *.log node_modules/ public/ .deploy*/ + # 主题构建生成的目标文件 themes/yilia/source/css/ themes/yilia/source/js/ diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..e63a1af --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,71 @@ +const gulp = require('gulp'), + htmlmin = require('gulp-htmlmin'), //html压缩组件 + htmlclean = require('gulp-htmlclean'), //html清理组件 + plumber = require('gulp-plumber'), //容错组件(发生错误不跳出任务,并报出错误内容) + Hexo = require('hexo') + +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: /