From 44b0d08a41e87c3a28891b5b331a95732e73059b Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 16 Feb 2021 22:58:55 -0500 Subject: [PATCH] Use minified js files for jsdelivr and cdnjs (#207) --- scripts/helpers/engine.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/helpers/engine.js b/scripts/helpers/engine.js index 8855e8f..0d7a4f3 100644 --- a/scripts/helpers/engine.js +++ b/scripts/helpers/engine.js @@ -18,11 +18,12 @@ hexo.extend.helper.register('next_inject', function(point) { hexo.extend.helper.register('next_js', function(file, pjax = false) { const { next_version } = this; const { internal } = this.theme.vendors; + const minified_file = file.endsWith('.js') && !file.endsWith('.min.js') ? file.slice(0, -3) + '.min.js' : file; const links = { local : this.url_for(`${this.theme.js}/${file}`), - jsdelivr: `https://cdn.jsdelivr.net/npm/hexo-theme-next@${next_version}/source/js/${file}`, + jsdelivr: `https://cdn.jsdelivr.net/npm/hexo-theme-next@${next_version}/source/js/${minified_file}`, unpkg : `https://unpkg.com/hexo-theme-next@${next_version}/source/js/${file}`, - cdnjs : `https://cdnjs.cloudflare.com/ajax/libs/hexo-theme-next/${next_version}/${file}` + cdnjs : `https://cdnjs.cloudflare.com/ajax/libs/hexo-theme-next/${next_version}/${minified_file}` }; const src = links[internal] || links.local; return ``;