Remove internal scripts if minify is true and the CDN provider is not local (#251)

This commit is contained in:
Jinzhe Zeng 2021-04-29 23:47:34 -04:00 committed by GitHub
parent e30159875a
commit 959e100298
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,10 +2,24 @@
'use strict';
const internalScripts = [];
hexo.theme.addProcessor('js/*', file => {
internalScripts.push(file.params[0]);
});
hexo.extend.filter.register('after_generate', () => {
const theme = hexo.theme.config;
if (!theme.minify) return;
if (theme.vendors.internal !== 'local') {
// Remove all internal scripts
internalScripts.forEach(path => {
hexo.route.remove(path);
});
return;
}
if (!hexo.locals.get('pages').some(page => page.type === 'schedule')) {
hexo.route.remove('js/schedule.js');
}