From 959e1002984524729456d4f4254e8962a03f8c48 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 29 Apr 2021 23:47:34 -0400 Subject: [PATCH] Remove internal scripts if `minify` is true and the CDN provider is not `local` (#251) --- scripts/filters/minify.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/filters/minify.js b/scripts/filters/minify.js index f3a8ff09f..e4f1839eb 100644 --- a/scripts/filters/minify.js +++ b/scripts/filters/minify.js @@ -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'); }