jsdelivr被墙,hexo-next切换为自定义CDN

Thank you all for your tests, feedback and support. I am personally sorry for the issues we had today.
We can consider the issue as resolved, now its a question of DNS propagation getting to everyone.
Our official announcement regarding the problems today:
Unfortunately today jsDelivr unexpectedly lost its ICP license in China. As effect the regional cdn disabled our account.

This resulted in the extended outage we had in mainland China and Taiwan.

Other regions were unaffected.

We understand how difficult it was for our users to experience this unique situation.

From now on all Chinese traffic will be served by “near China” locations provided by global CDN providers.

This will have the additional benefit of better failover logic in the future.

https://github.com/jsdelivr/jsdelivr/issues/18348#issuecomment-997777996

jsDelivr被吊销ICP许可证五个月后,cdn.jsdelivr.net开始遭到污染,非魔法上网已经不能正常加载,各中原因不做讨论,无外乎滥用

本博客使用 Hexo 框架和 NexT 主题,默认使用的是 JSDelivr 作为 静态资源的 CDN 服务提供商,为了能正常访问,所以需要切换到国内cdn

1. 升级Next主题

  • 使用npm管理的

     npm install hexo-theme-next@8.11.1 
  • 使用git仓库管理的使用git pull

2.修改Next主题CDN

修改本地_config.next.yml

  vendors:    internal: local    plugins: custom        custom_cdn_url: https://lib.baomitu.com/${cdnjs_name}/${version}/${cdnjs_file} 

3. 修改谷歌字体库

修改_config.next.yml配置项

font: enable: true  host: https://fonts.geekzu.org 

4.修改Valine

https://github.com/next-theme/hexo-next-valine/blob/main/valine.njk

... <script> document.addEventListener('page:loaded', () => { NexT.utils.loadComments(CONFIG.valine.el) .then(() => NexT.utils.getScript( 'https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js', { condition: window.Valine } )) .then(() => { new Valine(CONFIG.valine); }); }); </script> ... <script> NexT.utils.loadComments('#valine-comments', () => { NexT.utils.getScript('https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js', () => { new Valine(Object.assign({{ config.valine | safedump }}, { el: '#valine-comments', path: {{ url_for(page.path) | replace(r/index\.html$/, '') | safedump }}, serverURLs: {{ serverURLs | safedump }} })); }, window.Valine); }); </script> 

修改node_modules/hexo-next-valine/valine.njk

{%- if next_data %} {{ next_data('valine', config.valine, { el: '#valine-comments', path: url_for(page.path) | replace(r/index\.html$/, ''), libUrl: config.valine.libUrl | default('https://lib.baomitu.com/valine/latest/Valine.min.js',true), serverURLs: config.valine.serverURLs or 'https://' + config.valine.appId.slice(0, 8) | lower + '.api.lncldglobal.com' }) }} <script> document.addEventListener('page:loaded', () => { NexT.utils.loadComments(CONFIG.valine.el) .then(() => NexT.utils.getScript( CONFIG.valine.libUrl, { condition: window.Valine } )) .then(() => { new Valine(CONFIG.valine); }); }); </script> {%- else %} {%- set serverURLs = config.valine.serverURLs or 'https://' + config.valine.appId.slice(0, 8) | lower + '.api.lncldglobal.com' %} {%- set libUrl = config.valine.libUrl | default('https://lib.baomitu.com/valine/latest/Valine.min.js',true) %} <script> NexT.utils.loadComments('#valine-comments', () => { NexT.utils.getScript('{{libUrl}}', () => { new Valine(Object.assign({{ config.valine | safedump }}, { el: '#valine-comments', path: {{ url_for(page.path) | replace(r/index\.html$/, '') | safedump }}, serverURLs: {{ serverURLs | safedump }} })); }, window.Valine); }); </script> {%- endif %} 

使用patch-package修改node_module,配合github/actions使用

npm i patch-package -D 

生成补丁包

npx patch-package hexo-next-valine 

_config.next.yml增加配置项

valine: enable: true appId: xx  appKey: xx   libUrl: https://cdnjs.cloudflare.com/ajax/libs/valine/1.4.18/Valine.min.js 

原文链接:https://blog.csdn.net/tsvico/article/details/124852417?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165934458816782425171677%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165934458816782425171677&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-29-124852417-null-null.nonecase&utm_term=%E8%87%AA%E5%BB%BAcdn

原创文章,作者:优速盾-小U,如若转载,请注明出处:https://www.cdnb.net/bbs/archives/6180

(0)
上一篇 2022年9月18日
下一篇 2022年9月18日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

优速盾注册领取大礼包www.cdnb.net
/sitemap.xml