-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
62 lines (56 loc) · 1.41 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import type Hexo from 'hexo'
import { minifyHtml } from './lib/html'
import { minifyCss } from './lib/css'
import { minifyJs } from './lib/js'
import { replaceSrc, transformImage } from './lib/img'
declare const hexo:Hexo
hexo.config.minify.js = Object.assign({
enable: false,
options: {
comments: false,
ecma: 2020,
toplevel: false
},
exclude: []
}, hexo.config.minify?.js)
hexo.config.minify.css = Object.assign({
enable: true,
options: {
targets: null
},
exclude: []
}, hexo.config.minify?.css)
hexo.config.minify.html = Object.assign({
enable: true,
minifier: 'html-minifier',
options: {
comments: false
},
exclude: []
}, hexo.config.minify?.html)
hexo.config.minify.image = Object.assign({
enable: true,
options: {
webp: true,
avif: false,
quality: 80,
effort: 2,
replaceSrc: true
},
exclude: []
}, hexo.config.minify?.image)
if (hexo.config.minify.html.enable) {
hexo.extend.filter.register('after_render:html', minifyHtml)
}
if (hexo.config.minify.css.enable) {
hexo.extend.filter.register('after_render:css', minifyCss)
}
if (hexo.config.minify.js.enable) {
hexo.extend.filter.register('after_render:js', minifyJs)
}
if (hexo.config.minify.image.enable) {
hexo.extend.filter.register('after_generate', transformImage, 50)
if (hexo.config.minify.image.options.replaceSrc) {
hexo.extend.filter.register('after_render:html', replaceSrc, 1)
}
}