This repository has been archived by the owner on Jul 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.js
112 lines (89 loc) · 2.6 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
107
108
109
110
111
112
'use strict';
const filters = require('./lib/filters');
const revision = require('./lib/revision');
const config = hexo.config;
/**
* Start things is hexo.config.asset_pipeline is defined in _config.yaml.
*/
if(config.asset_pipeline){
/**
* CSS config.
*/
const cleanCssDefaults = {};
const cssConfig = {
exclude: ['*.min.css']
};
config.asset_pipeline.clean_css = Object.assign(cleanCssDefaults, cssConfig, config.asset_pipeline.clean_css || {});
hexo.extend.filter.register('after_render:css', filters.css);
/**
* Js config.
*/
const uglifyjsDefaults = {
mangle: true
};
const jsConfig = {
exclude: ['*.min.js']
};
config.asset_pipeline.uglify_js = Object.assign(uglifyjsDefaults, jsConfig, config.asset_pipeline.uglify_js || {});
hexo.extend.filter.register('after_render:js', filters.js);
/**
* HTML config.
*/
const htmlMinifierDefaults = {
ignoreCustomComments: [/^\s*more/],
removeComments: true,
removeCommentsFromCDATA: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeEmptyAttributes: true,
minifyJS: true,
minifyCSS: true
};
const htmlConfig = {
exclude: []
}
config.asset_pipeline.html_minifier = Object.assign(htmlMinifierDefaults, htmlConfig, config.asset_pipeline.html_minifier || {});
hexo.extend.filter.register('after_render:html', filters.html);
/**
* Image config.
*/
const imageminDefaults = {
interlaced: false,
multipass: false,
optimizationLevel: 3,
pngquant: false,
progressive: false
}
const imageConfig = {};
config.asset_pipeline.imagemin = Object.assign(imageminDefaults, imageConfig, config.asset_pipeline.imagemin || {});
hexo.extend.filter.register('after_generate', filters.image);
/**
* Hook to enable revisioning.
*/
const revisioningDefaults = {
exclude: []
};
const soupConfig = {
selectors: {
'img[data-src]': 'data-src',
'img[src]': 'src',
'link[rel="apple-touch-icon"]': 'href',
'link[rel="icon"]': 'href',
'link[rel="shortcut icon"]': 'href',
'link[rel="stylesheet"]': 'href',
'script[src]': 'src',
'source[src]': 'src',
'video[poster]': 'poster'
}
};
config.asset_pipeline.revisioning= Object.assign(revisioningDefaults, soupConfig, config.asset_pipeline.revisioning || {});
if(config.asset_pipeline.revisioning.enable){
hexo.extend.filter.register('after_generate', revision);
}
hexo.extend.filter.register('after_init', function(){
// Setup assetPipeline for caching data
hexo.assetPipeline = {
revIndex: {}
}
});
}