fix(cdn): patch cdn.js to make jsdelivr and unpkg work
parent
41f06e3d14
commit
d1bd500a14
|
@ -48,7 +48,7 @@ Share plugins
|
||||||
- [AddThis](http://ppoffice.github.io/hexo-theme-icarus/Plugins/Share/addthis-share-plugin/)
|
- [AddThis](http://ppoffice.github.io/hexo-theme-icarus/Plugins/Share/addthis-share-plugin/)
|
||||||
- [AddToAny](http://ppoffice.github.io/hexo-theme-icarus/Plugins/Share/addtoany-share-plugin/)
|
- [AddToAny](http://ppoffice.github.io/hexo-theme-icarus/Plugins/Share/addtoany-share-plugin/)
|
||||||
- [Baidu Share](http://ppoffice.github.io/hexo-theme-icarus/Plugins/Share/baidu-share-plugin/)
|
- [Baidu Share](http://ppoffice.github.io/hexo-theme-icarus/Plugins/Share/baidu-share-plugin/)
|
||||||
- [Share.js](http://ppoffice.github.io/hexo-theme-icarus/Plugins/Share/sharejs-share-plugin/)
|
- [Share.js](http://ppoffice.github.io/hexo-theme-icarus/Plugins/Share/share-js-share-plugin/)
|
||||||
- [ShareThis](http://ppoffice.github.io/hexo-theme-icarus/Plugins/Share/sharethis-share-plugin/)
|
- [ShareThis](http://ppoffice.github.io/hexo-theme-icarus/Plugins/Share/sharethis-share-plugin/)
|
||||||
|
|
||||||
Other plugins
|
Other plugins
|
||||||
|
|
|
@ -9,36 +9,56 @@
|
||||||
const cdn_providers = {
|
const cdn_providers = {
|
||||||
cdnjs: 'https://cdnjs.cloudflare.com/ajax/libs/${ package }/${ version }/${ filename }',
|
cdnjs: 'https://cdnjs.cloudflare.com/ajax/libs/${ package }/${ version }/${ filename }',
|
||||||
jsdelivr: 'https://cdn.jsdelivr.net/npm/${ package }@${ version }/${ filename }',
|
jsdelivr: 'https://cdn.jsdelivr.net/npm/${ package }@${ version }/${ filename }',
|
||||||
jsdelivr_github: 'https://cdn.jsdelivr.net/gh/user/${ package }@${ version }/${ filename }',
|
|
||||||
unpkg: 'https://unpkg.com/${ package }@${ version }/${ filename }'
|
unpkg: 'https://unpkg.com/${ package }@${ version }/${ filename }'
|
||||||
};
|
};
|
||||||
|
|
||||||
const font_providers = {
|
const font_providers = {
|
||||||
google: 'https://fonts.googleapis.com/css?family=${ fontname }'
|
google: 'https://fonts.googleapis.com/${ type }?family=${ fontname }'
|
||||||
};
|
};
|
||||||
|
|
||||||
const icon_providers = {
|
const icon_providers = {
|
||||||
fontawesome: 'https://use.fontawesome.com/releases/v5.4.1/css/all.css',
|
fontawesome: 'https://use.fontawesome.com/releases/v5.4.1/css/all.css'
|
||||||
material: 'https://fonts.googleapis.com/icon?family=Material+Icons'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = function (hexo) {
|
module.exports = function (hexo) {
|
||||||
hexo.extend.helper.register('cdn', function (package, version, filename) {
|
hexo.extend.helper.register('cdn', function (_package, version, filename) {
|
||||||
let provider = hexo.extend.helper.get('get_config').bind(this)('providers.cdn');
|
let provider = hexo.extend.helper.get('get_config').bind(this)('providers.cdn');
|
||||||
|
// cdn.js does not follow a GitHub npm style like jsdeliver and unpkg do. Patch it!
|
||||||
|
if (provider === 'cdnjs' || provider.startsWith('[cdnjs]')) {
|
||||||
|
if (provider.startsWith('[cdnjs]')) {
|
||||||
|
provider = provider.substr(7);
|
||||||
|
}
|
||||||
|
if (filename.startsWith('dist/')) {
|
||||||
|
filename = filename.substr(5);
|
||||||
|
}
|
||||||
|
if (_package === 'moment') {
|
||||||
|
_package = 'moment.js';
|
||||||
|
filename = filename.startsWith('min/') ? filename.substr(4) : filename;
|
||||||
|
}
|
||||||
|
if (_package === 'outdatedbrowser') {
|
||||||
|
_package = 'outdated-browser';
|
||||||
|
filename = filename.startsWith('outdatedbrowser/') ? filename.substr(16) : filename;
|
||||||
|
}
|
||||||
|
if (_package === 'highlight.js') {
|
||||||
|
filename = filename.endsWith('.css') && filename.indexOf('.min.') === -1 ?
|
||||||
|
filename.substr(0, filename.length - 4) + '.min.css' : filename;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (provider !== null && cdn_providers.hasOwnProperty(provider)) {
|
if (provider !== null && cdn_providers.hasOwnProperty(provider)) {
|
||||||
provider = cdn_providers[provider];
|
provider = cdn_providers[provider];
|
||||||
}
|
}
|
||||||
return provider.replace(/\${\s*package\s*}/gi, package)
|
return provider.replace(/\${\s*package\s*}/gi, _package)
|
||||||
.replace(/\${\s*version\s*}/gi, version)
|
.replace(/\${\s*version\s*}/gi, version)
|
||||||
.replace(/\${\s*filename\s*}/gi, filename);
|
.replace(/\${\s*filename\s*}/gi, filename);
|
||||||
});
|
});
|
||||||
|
|
||||||
hexo.extend.helper.register('fontcdn', function (fontName) {
|
hexo.extend.helper.register('fontcdn', function (fontName, type = 'css') {
|
||||||
let provider = hexo.extend.helper.get('get_config').bind(this)('providers.fontcdn');
|
let provider = hexo.extend.helper.get('get_config').bind(this)('providers.fontcdn');
|
||||||
if (provider !== null && font_providers.hasOwnProperty(provider)) {
|
if (provider !== null && font_providers.hasOwnProperty(provider)) {
|
||||||
provider = font_providers[provider];
|
provider = font_providers[provider];
|
||||||
}
|
}
|
||||||
return provider.replace(/\${\s*fontname\s*}/gi, fontName);
|
return provider.replace(/\${\s*fontname\s*}/gi, fontName)
|
||||||
|
.replace(/\${\s*type\s*}/gi, type);
|
||||||
});
|
});
|
||||||
|
|
||||||
hexo.extend.helper.register('iconcdn', function (provider = null) {
|
hexo.extend.helper.register('iconcdn', function (provider = null) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ module.exports = {
|
||||||
cdn: {
|
cdn: {
|
||||||
[type]: 'string',
|
[type]: 'string',
|
||||||
[doc]: 'Name or URL of the JavaScript and/or stylesheet CDN provider',
|
[doc]: 'Name or URL of the JavaScript and/or stylesheet CDN provider',
|
||||||
[defaultValue]: 'cdnjs'
|
[defaultValue]: 'jsdelivr'
|
||||||
},
|
},
|
||||||
fontcdn: {
|
fontcdn: {
|
||||||
[type]: 'string',
|
[type]: 'string',
|
||||||
|
|
|
@ -23,9 +23,9 @@
|
||||||
|
|
||||||
<%- css(cdn('bulma', '0.7.2', 'css/bulma.css')) %>
|
<%- css(cdn('bulma', '0.7.2', 'css/bulma.css')) %>
|
||||||
<%- css(iconcdn()) %>
|
<%- css(iconcdn()) %>
|
||||||
<%- css(iconcdn('material')) %>
|
<%- css(fontcdn('Material+Icons', 'icon')) %>
|
||||||
<%- css(fontcdn('Ubuntu:400,600|Source+Code+Pro')) %>
|
<%- css(fontcdn('Ubuntu:400,600|Source+Code+Pro')) %>
|
||||||
<%- css(cdn('highlight.js', '9.12.0', 'styles/' + get_config('article.highlight') + '.min.css')) %>
|
<%- css(cdn('highlight.js', '9.12.0', 'styles/' + get_config('article.highlight') + '.css')) %>
|
||||||
<%- css('css/style') %>
|
<%- css('css/style') %>
|
||||||
|
|
||||||
<% if (has_config('plugins')) { %>
|
<% if (has_config('plugins')) { %>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<%- js(cdn('jquery', '3.3.1', 'jquery.min.js')) %>
|
<%- js(cdn('jquery', '3.3.1', 'dist/jquery.min.js')) %>
|
||||||
<%- js(cdn('moment.js', '2.22.2', 'moment-with-locales.min.js')) %>
|
<%- js(cdn('moment', '2.22.2', 'min/moment-with-locales.min.js')) %>
|
||||||
<script>moment.locale("<%= get_config('language', 'en') %>");</script>
|
<script>moment.locale("<%= get_config('language', 'en') %>");</script>
|
||||||
|
|
||||||
<% if (has_config('plugins')) { %>
|
<% if (has_config('plugins')) { %>
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<% if (plugin !== false) { %>
|
<% if (plugin !== false) { %>
|
||||||
<% if (head) { %>
|
<% if (head) { %>
|
||||||
<%- css(cdn('lightgallery', '1.6.8', 'css/lightgallery.min.css')) %>
|
<%- css(cdn('lightgallery', '1.6.8', 'dist/css/lightgallery.min.css')) %>
|
||||||
<%- css(cdn('justifiedGallery', '3.7.0', 'css/justifiedGallery.min.css')) %>
|
<%- css(cdn('justifiedGallery', '3.7.0', 'dist/css/justifiedGallery.min.css')) %>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
<%- js(cdn('lightgallery', '1.6.8', 'js/lightgallery-all.min.js')) %>
|
<%- js(cdn('lightgallery', '1.6.8', 'dist/js/lightgallery.min.js')) %>
|
||||||
<%- js(cdn('justifiedGallery', '3.7.0', 'js/jquery.justifiedGallery.min.js')) %>
|
<%- js(cdn('justifiedGallery', '3.7.0', 'dist/js/jquery.justifiedGallery.min.js')) %>
|
||||||
<script>
|
<script>
|
||||||
(function ($) {
|
(function ($) {
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
<% if (plugin !== false) { %>
|
<% if (plugin !== false) { %>
|
||||||
<% if (head) { %>
|
<% if (head) { %>
|
||||||
<%- css(cdn('outdated-browser', '1.1.5', 'outdatedbrowser.min.css')) %>
|
<%- css(cdn('outdatedbrowser', '1.1.5', 'outdatedbrowser/outdatedbrowser.min.css')) %>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
<div id="outdated">
|
<div id="outdated">
|
||||||
<h6>Your browser is out-of-date!</h6>
|
<h6>Your browser is out-of-date!</h6>
|
||||||
<p>Update your browser to view this website correctly. <a id="btnUpdateBrowser" href="http://outdatedbrowser.com/">Update my browser now </a></p>
|
<p>Update your browser to view this website correctly. <a id="btnUpdateBrowser" href="http://outdatedbrowser.com/">Update my browser now </a></p>
|
||||||
<p class="last"><a href="#" id="btnCloseUpdateBrowser" title="Close">×</a></p>
|
<p class="last"><a href="#" id="btnCloseUpdateBrowser" title="Close">×</a></p>
|
||||||
</div>
|
</div>
|
||||||
<%- js(cdn('outdated-browser', '1.1.5', 'outdatedbrowser.min.js')) %>
|
<%- js(cdn('outdatedbrowser', '1.1.5', 'outdatedbrowser/outdatedbrowser.min.js')) %>
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
// plugin function, place inside DOM ready function
|
// plugin function, place inside DOM ready function
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
<div class="social-share"></div>
|
<div class="social-share"></div>
|
||||||
<%- css(cdn('social-share.js', '1.0.16', 'css/share.min.css')) %>
|
<%- css(cdn('social-share.js', '1.0.16', 'dist/css/share.min.css')) %>
|
||||||
<%- js(cdn('social-share.js', '1.0.16', 'js/social-share.min.js')) %>
|
<%- js(cdn('social-share.js', '1.0.16', 'dist/js/social-share.min.js')) %>
|
Loading…
Reference in New Issue