/
index.js
106 lines (94 loc) · 3.52 KB
/
index.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* global hexo */
'use strict';
const assign = require('object-assign');
//module.exports = function (hexo) {
let hexoCommands = (hexo.env.args && hexo.env.args._) || [];
if(hexo.env.debug === true || hexoCommands.includes('clean')) return;
if (false === hexo.config.hasOwnProperty('filter_cleanup') || true === hexo.config.filter_cleanup) {
// HTML Useref
hexo.config.hfc_useref = assign({
enable: true,
exclude: [],
concat: true
}, hexo.config.hfc_useref);
// HTML minifier
hexo.config.hfc_html = assign({
enable: true,
exclude: [],
ignoreCustomComments: [/^\s*more/],
removeComments: true,
removeCommentsFromCDATA: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeEmptyAttributes: true,
minifyJS: true,
minifyCSS: true,
}, hexo.config.hfc_html);
// Css minifier
hexo.config.hfc_css = assign({
enable: true,
exclude: ['*.min.css']
}, hexo.config.hfc_css);
// Js minifier
hexo.config.hfc_js = assign({
enable: true,
mangle: true,
compress: {},
exclude: ['*.min.js']
}, hexo.config.hfc_js, {});
// Image minifier
hexo.config.hfc_img = assign({
enable: true,
exclude: [],
interlaced: false,
multipass: false,
optimizationLevel: 3,
pngquant: false,
webp: true,
webpQuality: 75,
gifslice: true,
jpegtran: true,
jpegrecompress: false,
jpegrecompressQuality: 'medium',
optipng: true,
svgo: true,
progressive: false
}, hexo.config.hfc_img);
// Favicons
hexo.config.hfc_favicons = assign({
enable: true,
src: 'img/logo.png',
html: true,
target:'img/',
// extra favicons configs
opts: false,
icons: {
// Create Android homescreen icon. `boolean`
android: true,
// Create Apple touch icons. `boolean`
appleIcon: true,
// Create Apple startup images. `boolean`
appleStartup: false,
// Create Opera Coast icon. `boolean`
coast: false,
// Create regular favicons. `boolean`
favicons: true,
// Create Firefox OS icons. `boolean`
firefox: false,
// Create Facebook OpenGraph. `boolean`
opengraph: false,
// Create Windows 8 tiles. `boolean`
windows: true,
// Create Yandex browser icon. `boolean`
yandex: false
}
}, hexo.config.hfc_favicons);
let filter = require('./lib');
hexo.extend.filter.register('after_render:css', filter.optimizeCSS);
hexo.extend.filter.register('after_render:js', filter.optimizeJS);
hexo.extend.filter.register('after_init', filter.genFavicons);
hexo.extend.filter.register('after_generate', filter.optimizeImage);
hexo.extend.filter.register('after_generate', filter.userefHTML);
hexo.extend.filter.register('after_generate', filter.optimizeHTML);
}
//}