Skip to content

Commit

Permalink
Remove internal scripts if minify is true and the CDN provider is n…
Browse files Browse the repository at this point in the history
…ot `local` (#251)
  • Loading branch information
njzjz authored Apr 30, 2021
1 parent e301598 commit 959e100
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions scripts/filters/minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down

0 comments on commit 959e100

Please sign in to comment.