hexo-yam/index.js

143 lines
4.2 KiB
JavaScript
Raw Normal View History

2016-05-26 11:09:41 +00:00
/* global hexo */
2019-05-27 01:14:04 +00:00
'use strict'
2024-12-02 08:48:09 +00:00
hexo.config.minify = {
enable: true,
2024-12-02 08:48:09 +00:00
previewServer: true,
...hexo.config.minify
}
2024-12-02 08:48:09 +00:00
hexo.config.minify.html = {
2020-09-05 11:41:22 +00:00
enable: true,
priority: 10,
verbose: false,
exclude: [],
collapseBooleanAttributes: true,
collapseWhitespace: true,
// Ignore '<!-- more -->' https://hexo.io/docs/tag-plugins#Post-Excerpt
ignoreCustomComments: [/^\s*more/],
removeComments: true,
removeEmptyAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
minifyJS: true,
minifyCSS: true,
2024-12-02 08:48:09 +00:00
globOptions: { basename: true },
...hexo.config.minify.html
}
2020-09-05 11:41:22 +00:00
2024-12-02 08:48:09 +00:00
hexo.config.minify.css = {
2020-09-05 11:41:22 +00:00
enable: true,
priority: 10,
verbose: false,
exclude: ['*.min.css'],
level: 2,
2024-12-02 08:48:09 +00:00
globOptions: { basename: true },
...hexo.config.minify.css
}
2020-09-05 11:41:22 +00:00
2024-12-02 08:48:09 +00:00
hexo.config.minify.js = {
2020-09-05 11:41:22 +00:00
enable: true,
priority: 10,
verbose: false,
exclude: ['*.min.js'],
compress: {},
mangle: true,
output: {},
2024-12-02 08:48:09 +00:00
globOptions: { basename: true },
...hexo.config.minify.js
}
2020-09-05 11:41:22 +00:00
2024-12-02 08:48:09 +00:00
hexo.config.minify.svg = {
2020-09-05 11:41:22 +00:00
enable: true,
priority: 10,
verbose: false,
include: ['*.svg', '!*.min.svg'],
plugins: {},
2024-12-02 08:48:09 +00:00
globOptions: { basename: true },
...hexo.config.minify.svg
}
2020-09-05 11:41:22 +00:00
hexo.config.minify.xml = {
enable: false,
2020-09-05 11:41:22 +00:00
priority: 10,
verbose: false,
include: ['*.xml', '!*.min.xml'],
removeComments: true,
2024-12-02 08:48:09 +00:00
globOptions: { basename: true },
...hexo.config.minify.xml
2024-12-02 08:48:09 +00:00
}
2020-09-05 11:41:22 +00:00
hexo.config.minify.json = {
enable: false,
2020-09-05 11:41:22 +00:00
priority: 10,
verbose: false,
include: ['*.json', '*.webmanifest', '!*.min.json', '!*.min.webmanifest'],
2024-12-02 08:48:09 +00:00
globOptions: { basename: true },
...hexo.config.minify.json
2024-12-02 08:48:09 +00:00
}
2020-09-05 11:41:22 +00:00
hexo.config.minify.gzip = {
enable: true,
priority: 10,
verbose: false,
include: ['*.html', '*.css', '*.js', '*.txt', '*.ttf', '*.atom', '*.stl', '*.xml', '*.svg', '*.eot', '*.json', '*.webmanifest'],
2024-12-02 08:48:09 +00:00
globOptions: { basename: true },
...hexo.config.minify.gzip
2024-12-02 08:48:09 +00:00
}
hexo.config.minify.brotli = {
enable: true,
2020-09-05 11:41:22 +00:00
priority: 10,
verbose: false,
include: ['*.html', '*.css', '*.js', '*.txt', '*.ttf', '*.atom', '*.stl', '*.xml', '*.svg', '*.eot', '*.json', '*.webmanifest'],
2024-12-02 08:48:09 +00:00
globOptions: { basename: true },
...hexo.config.minify.brotli
2024-12-02 08:48:09 +00:00
}
2020-09-05 11:41:22 +00:00
hexo.config.minify.zstd = {
2020-09-05 11:41:22 +00:00
enable: false,
priority: 10,
verbose: false,
include: ['*.html', '*.css', '*.js', '*.txt', '*.ttf', '*.atom', '*.stl', '*.xml', '*.svg', '*.eot', '*.json', '*.webmanifest'],
2024-12-02 08:48:09 +00:00
globOptions: { basename: true },
...hexo.config.minify.zstd
2024-12-02 08:48:09 +00:00
}
2020-09-05 11:41:22 +00:00
if (hexo.config.minify.enable === true && !(hexo.config.minify.previewServer === true && ['s', 'server'].includes(hexo.env.cmd))) {
2024-12-02 08:48:09 +00:00
if (hexo.config.minify.html.enable === true) {
hexo.extend.filter.register('after_render:html', require('./lib/html').minifyHtml, hexo.config.minify.html.priority)
}
if (hexo.config.minify.css.enable === true) {
hexo.extend.filter.register('after_render:css', require('./lib/css').minifyCss, hexo.config.minify.css.priority)
}
if (hexo.config.minify.js.enable === true) {
hexo.extend.filter.register('after_render:js', require('./lib/js').minifyJs, hexo.config.minify.js.priority)
}
if (hexo.config.minify.svg.enable === true) {
hexo.extend.filter.register('after_generate', require('./lib/svg').minifySvg, hexo.config.minify.svg.priority)
}
if (hexo.config.minify.xml.enable === true) {
hexo.extend.filter.register('after_generate', require('./lib/xml').minifyXml, hexo.config.minify.xml.priority)
}
if (hexo.config.minify.json.enable === true) {
hexo.extend.filter.register('after_generate', require('./lib/json').minifyJson, hexo.config.minify.json.priority)
}
2024-12-02 08:48:09 +00:00
if (hexo.config.minify.gzip.enable || hexo.config.minify.brotli.enable) {
const zlib = require('./lib/zlib')
if (hexo.config.minify.gzip.enable === true) {
hexo.extend.filter.register('after_generate', zlib.gzipFn, hexo.config.minify.gzip.priority)
}
if (hexo.config.minify.brotli.enable === true) {
hexo.extend.filter.register('after_generate', zlib.brotliFn, hexo.config.minify.brotli.priority)
}
}
if (hexo.config.minify.zstd.enable === true) {
try {
hexo.extend.filter.register('after_generate', require('./lib/zstd').zstdFn, hexo.config.minify.zstd.priority)
} catch (ex) {
const log = hexo.log || console
log.warn(`ZSTD load failed. ${ex}`)
}
}
}