From 9fa79f78d156ecccad5558b06e71b07017140d60 Mon Sep 17 00:00:00 2001 From: wherewhere Date: Tue, 14 Jan 2025 16:59:59 +0800 Subject: [PATCH] feat: add hexo type define --- index.js | 2 ++ lib/css.js | 4 ++++ lib/html.js | 1 + lib/js.js | 4 ++++ lib/json.js | 3 +++ lib/svg.js | 3 +++ lib/xml.js | 3 +++ lib/zlib.js | 6 ++++++ lib/zstd.js | 3 +++ 9 files changed, 29 insertions(+) diff --git a/index.js b/index.js index 85d4033..15ab3e6 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,8 @@ /* global hexo */ 'use strict' +/** @typedef {import("@types/hexo")} */ + hexo.config.minify = { enable: true, previewServer: true, diff --git a/lib/css.js b/lib/css.js index 269e826..e7a8e58 100644 --- a/lib/css.js +++ b/lib/css.js @@ -5,6 +5,7 @@ const { isMatch, match, logFn } = require('./tools') /** * @param {string} str * @param {{ path: string }} data + * @this {import('@types/hexo')} */ async function minifyCss(str, data) { const hexo = this @@ -25,6 +26,9 @@ async function minifyCss(str, data) { } } +/** + * @this {import('@types/hexo')} + */ function minifyCssWithMap() { const hexo = this const options = hexo.config.minify.css diff --git a/lib/html.js b/lib/html.js index bfcb758..863a3b0 100644 --- a/lib/html.js +++ b/lib/html.js @@ -5,6 +5,7 @@ const { isMatch, logFn } = require('./tools') /** * @param {string} str * @param {{ path: string }} data + * @this {import('@types/hexo')} */ async function minifyHtml(str, data) { const hexo = this diff --git a/lib/js.js b/lib/js.js index 50f5955..251bb2d 100644 --- a/lib/js.js +++ b/lib/js.js @@ -5,6 +5,7 @@ const { isMatch, match, logFn } = require('./tools') /** * @param {string} str * @param {{ path: string }} data + * @this {import('@types/hexo')} */ async function minifyJs(str, data) { const hexo = this @@ -31,6 +32,9 @@ async function minifyJs(str, data) { } } +/** + * @this {import('@types/hexo')} + */ function minifyJsWithMap() { const hexo = this const options = hexo.config.minify.js diff --git a/lib/json.js b/lib/json.js index 287ceaf..9f40e51 100644 --- a/lib/json.js +++ b/lib/json.js @@ -1,6 +1,9 @@ 'use strict' const { match, logFn } = require('./tools') +/** + * @this {import('@types/hexo')} + */ function minifyJson() { const hexo = this const options = hexo.config.minify.json diff --git a/lib/svg.js b/lib/svg.js index f8d478a..0cfb0e0 100644 --- a/lib/svg.js +++ b/lib/svg.js @@ -2,6 +2,9 @@ const { optimize: svgOptimize } = require('svgo') const { match, logFn } = require('./tools') +/** + * @this {import('@types/hexo')} + */ function minifySvg() { const hexo = this const options = hexo.config.minify.svg diff --git a/lib/xml.js b/lib/xml.js index 9d5799f..d13061c 100644 --- a/lib/xml.js +++ b/lib/xml.js @@ -1,6 +1,9 @@ 'use strict' const { match, logFn } = require('./tools') +/** + * @this {import('@types/hexo')} + */ async function minifyXml() { const { minify: compressXml } = await import('minify-xml') diff --git a/lib/zlib.js b/lib/zlib.js index e3de80b..7b0a0c2 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -5,6 +5,9 @@ const gzip = promisify(zlib.gzip) const br = promisify(zlib.brotliCompress) const { match, logFn } = require('./tools') +/** + * @this {import('@types/hexo')} + */ function gzipFn() { const hexo = this const options = hexo.config.minify.gzip @@ -40,6 +43,9 @@ function gzipFn() { })) } +/** + * @this {import('@types/hexo')} + */ function brotliFn() { const hexo = this const options = hexo.config.minify.brotli diff --git a/lib/zstd.js b/lib/zstd.js index a0ecf36..1b6701c 100644 --- a/lib/zstd.js +++ b/lib/zstd.js @@ -25,6 +25,9 @@ function importZstd() { const { compress: zstd, init = undefined } = importZstd() const { match, logFn } = require('./tools') +/** + * @this {import('@types/hexo')} + */ async function zstdFn() { const hexo = this const options = hexo.config.minify.zstd