Use minified js files for jsdelivr and cdnjs (#207)

This commit is contained in:
Jinzhe Zeng 2021-02-16 22:58:55 -05:00 committed by GitHub
parent 538b06c7e8
commit 44b0d08a41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 `<script ${pjax ? 'data-pjax ' : ''}src="${src}"></script>`;