学习
实践
活动
专区
工具
TVP
写文章
专栏首页pai233的专栏快速将Butterfly主题的CDN从jsDelivr切换至自建反向代理源

快速将Butterfly主题的CDN从jsDelivr切换至自建反向代理源

最新版的Butterfly取消了原来设置在_config.yml里的默认CDN,导致不能快速替换掉现在极不稳定的jsDelivr CDN。本文的默认Butterfly版本为4.1.0

配置

现在的默认CDN地址被放在了主题的/scripts/events/config.js中:

/**
 * Butterfly
 * 1. Merge CDN
 * 2. Capitalize the first letter of comment name
 */

'use strict'

hexo.extend.filter.register('before_generate', () => {
  const themeConfig = hexo.theme.config

  /**
   * Merge CDN
   */

  const defaultCDN = {
    main_css: '/css/index.css',
    main: '/js/main.js',
    utils: '/js/utils.js',

    // pjax
    pjax: 'https://cdn.jsdelivr.net/npm/pjax/pjax.min.js',

    // comments
    gitalk: 'https://cdn.jsdelivr.net/npm/gitalk@latest/dist/gitalk.min.js',
    gitalk_css: 'https://cdn.jsdelivr.net/npm/gitalk/dist/gitalk.min.css',
    blueimp_md5: 'https://cdn.jsdelivr.net/npm/blueimp-md5/js/md5.min.js',
    valine: 'https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js',
    disqusjs: 'https://cdn.jsdelivr.net/npm/disqusjs@1/dist/disqus.js',
    disqusjs_css: 'https://cdn.jsdelivr.net/npm/disqusjs@1/dist/disqusjs.css',
    utterances: 'https://utteranc.es/client.js',
    twikoo: 'https://cdn.jsdelivr.net/npm/twikoo/dist/twikoo.all.min.js',
    waline: 'https://cdn.jsdelivr.net/npm/@waline/client/dist/Waline.min.js',
    giscus: 'https://giscus.app/client.js',

    // share
    addtoany: 'https://static.addtoany.com/menu/page.js',
    sharejs: 'https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js',
    sharejs_css: 'https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css',

    // search
    local_search: '/js/search/local-search.js',
    algolia_js: '/js/search/algolia.js',
    algolia_search_v4: 'https://cdn.jsdelivr.net/npm/algoliasearch@4/dist/algoliasearch-lite.umd.js',
    instantsearch_v4: 'https://cdn.jsdelivr.net/npm/instantsearch.js@4/dist/instantsearch.production.min.js',

    // math
    mathjax: 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js',
    katex: 'https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css',
    katex_copytex: 'https://cdn.jsdelivr.net/npm/katex@latest/dist/contrib/copy-tex.min.js',
    katex_copytex_css: 'https://cdn.jsdelivr.net/npm/katex@latest/dist/contrib/copy-tex.css',
    mermaid: 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js',

    // count
    busuanzi: '//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js',

    // background effect
    canvas_ribbon: 'https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js',
    canvas_fluttering_ribbon: 'https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js',
    canvas_nest: 'https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-nest.min.js',

    lazyload: 'https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js',
    instantpage: 'https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js',
    typed: 'https://cdn.jsdelivr.net/npm/typed.js/lib/typed.min.js',
    pangu: 'https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js',

    // photo
    fancybox_css_v4: 'https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css',
    fancybox_v4: 'https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js',
    medium_zoom: 'https://cdn.jsdelivr.net/npm/medium-zoom/dist/medium-zoom.min.js',

    // snackbar
    snackbar_css: 'https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css',
    snackbar: 'https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js',

    // effect
    activate_power_mode: 'https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js',
    fireworks: 'https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js',
    click_heart: 'https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js',
    ClickShowText: 'https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-show-text.min.js',

    // fontawesome
    fontawesomeV6: 'https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css',

    // Conversion between Traditional and Simplified Chinese
    translate: '/js/tw_cn.js',

    // flickr-justified-gallery
    flickr_justified_gallery_js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
    flickr_justified_gallery_css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css',

    // aplayer
    aplayer_css: 'https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css',
    aplayer_js: 'https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js',
    meting_js: 'https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js',

    // Prism.js
    prismjs_js: 'https://cdn.jsdelivr.net/npm/prismjs/prism.min.js',
    prismjs_lineNumber_js: 'https://cdn.jsdelivr.net/npm/prismjs/plugins/line-numbers/prism-line-numbers.min.js',
    prismjs_autoloader: 'https://cdn.jsdelivr.net/npm/prismjs/plugins/autoloader/prism-autoloader.min.js'
  }

  // delete null value
  const deleteNullValue = obj => {
    for (const i in obj) {
      obj[i] === null && delete obj[i]
    }
    return obj
  }

  themeConfig.CDN = Object.assign(defaultCDN, deleteNullValue(themeConfig.CDN))

  /**
   * Capitalize the first letter of comment name
   */

  let { use } = themeConfig.comments

  if (!use) return

  if (typeof use === 'string') {
    use = use.split(',')
  }

  const newArray = use.map(item => item.toLowerCase().replace(/\b[a-z]/g, s => s.toUpperCase()))

  themeConfig.comments.use = newArray
})

所以只要快速替换掉这里的CDN,就可以切换到我们自建的CDN上。

成果

cdn.jsdelivr.net全部替换为自己的反代源后,成果就诞生了:

/**
 * Butterfly
 * 1. Merge CDN
 * 2. Capitalize the first letter of comment name
 */

'use strict'

hexo.extend.filter.register('before_generate', () => {
  const themeConfig = hexo.theme.config

  /**
   * Merge CDN
   */

  const defaultCDN = {
    main_css: '/css/index.css',
    main: '/js/main.js',
    utils: '/js/utils.js',

    // pjax
    pjax: 'https://jsdelivr.pai233.top/npm/pjax/pjax.min.js',

    // comments
    gitalk: 'https://jsdelivr.pai233.top/npm/gitalk@latest/dist/gitalk.min.js',
    gitalk_css: 'https://jsdelivr.pai233.top/npm/gitalk/dist/gitalk.min.css',
    blueimp_md5: 'https://jsdelivr.pai233.top/npm/blueimp-md5/js/md5.min.js',
    valine: 'https://jsdelivr.pai233.top/npm/valine/dist/Valine.min.js',
    disqusjs: 'https://jsdelivr.pai233.top/npm/disqusjs@1/dist/disqus.js',
    disqusjs_css: 'https://jsdelivr.pai233.top/npm/disqusjs@1/dist/disqusjs.css',
    utterances: 'https://utteranc.es/client.js',
    twikoo: 'https://jsdelivr.pai233.top/npm/twikoo/dist/twikoo.all.min.js',
    waline: 'https://jsdelivr.pai233.top/npm/@waline/client/dist/Waline.min.js',
    giscus: 'https://giscus.app/client.js',

    // share
    addtoany: 'https://static.addtoany.com/menu/page.js',
    sharejs: 'https://jsdelivr.pai233.top/npm/social-share.js/dist/js/social-share.min.js',
    sharejs_css: 'https://jsdelivr.pai233.top/npm/social-share.js/dist/css/share.min.css',

    // search
    local_search: '/js/search/local-search.js',
    algolia_js: '/js/search/algolia.js',
    algolia_search_v4: 'https://jsdelivr.pai233.top/npm/algoliasearch@4/dist/algoliasearch-lite.umd.js',
    instantsearch_v4: 'https://jsdelivr.pai233.top/npm/instantsearch.js@4/dist/instantsearch.production.min.js',

    // math
    mathjax: 'https://jsdelivr.pai233.top/npm/mathjax@3/es5/tex-mml-chtml.js',
    katex: 'https://jsdelivr.pai233.top/npm/katex@latest/dist/katex.min.css',
    katex_copytex: 'https://jsdelivr.pai233.top/npm/katex@latest/dist/contrib/copy-tex.min.js',
    katex_copytex_css: 'https://jsdelivr.pai233.top/npm/katex@latest/dist/contrib/copy-tex.css',
    mermaid: 'https://jsdelivr.pai233.top/npm/mermaid/dist/mermaid.min.js',

    // count
    busuanzi: '//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js',

    // background effect
    canvas_ribbon: 'https://jsdelivr.pai233.top/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js',
    canvas_fluttering_ribbon: 'https://jsdelivr.pai233.top/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js',
    canvas_nest: 'https://jsdelivr.pai233.top/npm/butterfly-extsrc@1/dist/canvas-nest.min.js',

    lazyload: 'https://jsdelivr.pai233.top/npm/vanilla-lazyload/dist/lazyload.iife.min.js',
    instantpage: 'https://jsdelivr.pai233.top/npm/instant.page/instantpage.min.js',
    typed: 'https://jsdelivr.pai233.top/npm/typed.js/lib/typed.min.js',
    pangu: 'https://jsdelivr.pai233.top/npm/pangu/dist/browser/pangu.min.js',

    // photo
    fancybox_css_v4: 'https://jsdelivr.pai233.top/npm/@fancyapps/ui/dist/fancybox.css',
    fancybox_v4: 'https://jsdelivr.pai233.top/npm/@fancyapps/ui/dist/fancybox.umd.js',
    medium_zoom: 'https://jsdelivr.pai233.top/npm/medium-zoom/dist/medium-zoom.min.js',

    // snackbar
    snackbar_css: 'https://jsdelivr.pai233.top/npm/node-snackbar/dist/snackbar.min.css',
    snackbar: 'https://jsdelivr.pai233.top/npm/node-snackbar/dist/snackbar.min.js',

    // effect
    activate_power_mode: 'https://jsdelivr.pai233.top/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js',
    fireworks: 'https://jsdelivr.pai233.top/npm/butterfly-extsrc@1/dist/fireworks.min.js',
    click_heart: 'https://jsdelivr.pai233.top/npm/butterfly-extsrc@1/dist/click-heart.min.js',
    ClickShowText: 'https://jsdelivr.pai233.top/npm/butterfly-extsrc@1/dist/click-show-text.min.js',

    // fontawesome
    fontawesomeV6: 'https://jsdelivr.pai233.top/npm/@fortawesome/fontawesome-free@6/css/all.min.css',

    // Conversion between Traditional and Simplified Chinese
    translate: '/js/tw_cn.js',

    // flickr-justified-gallery
    flickr_justified_gallery_js: 'https://jsdelivr.pai233.top/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
    flickr_justified_gallery_css: 'https://jsdelivr.pai233.top/npm/flickr-justified-gallery@2/dist/fjGallery.min.css',

    // aplayer
    aplayer_css: 'https://jsdelivr.pai233.top/npm/aplayer/dist/APlayer.min.css',
    aplayer_js: 'https://jsdelivr.pai233.top/npm/aplayer/dist/APlayer.min.js',
    meting_js: 'https://jsdelivr.pai233.top/gh/metowolf/MetingJS@1.2/dist/Meting.min.js',

    // Prism.js
    prismjs_js: 'https://jsdelivr.pai233.top/npm/prismjs/prism.min.js',
    prismjs_lineNumber_js: 'https://jsdelivr.pai233.top/npm/prismjs/plugins/line-numbers/prism-line-numbers.min.js',
    prismjs_autoloader: 'https://jsdelivr.pai233.top/npm/prismjs/plugins/autoloader/prism-autoloader.min.js'
  }

  // delete null value
  const deleteNullValue = obj => {
    for (const i in obj) {
      obj[i] === null && delete obj[i]
    }
    return obj
  }

  themeConfig.CDN = Object.assign(defaultCDN, deleteNullValue(themeConfig.CDN))

  /**
   * Capitalize the first letter of comment name
   */

  let { use } = themeConfig.comments

  if (!use) return

  if (typeof use === 'string') {
    use = use.split(',')
  }

  const newArray = use.map(item => item.toLowerCase().replace(/\b[a-z]/g, s => s.toUpperCase()))

  themeConfig.comments.use = newArray
})

替换完后,运行hexo cl && hexo g -d部署后,就成功切换到了你的反代源上。你也可以直接复制博主的成果进行使用~

本文参与 腾讯云自媒体分享计划 ,欢迎热爱写作的你一起参与!
本文分享自作者个人站点/博客:https://blog.pai233.top复制
如有侵权,请联系 cloudcommunity@tencent.com 删除。
登录 后参与评论
0 条评论

推荐阅读

  • 用了这么久 IDEA,你竟然不知道 Live Templates ?

    Live Templates 是什么,听上去感觉挺玄乎的。有的同学用过之后觉得简直太好用了,不能说大大提高了开发效率吧,至少也是小小的提高一下,节省了很多敲重复代码的时间。有的同学用过之后说:没什么用,奇技淫巧罢了。

    古时的风筝
    IDEJava编程算法
  • Safari脚本编辑使用体验

    背景是这样的,我在用 Safari看hackingwithswift这个网站时,感觉上方的一直固定的红色的和黑色的两条,如下图,太醒目了,于是便想,如何能把它们移除.

    莫空9081
    iOS
  • go gin框架和springboot框架WEB接口性能对比

    最近接触到go lang,真的被go的goroutine(协程)惊艳到了,一句 go function(){#todo},即可完成一个并发的工作。

    壮壮熊
    GoHTTPhttps网络安全打包
  • 【Blender】如何使用Festivity方案一键三渲二 - FBX版本

    若直接使用3d渲染,需要考虑场景光照是否真实,人物面部光线,全局光,光线追踪等等,同时受限于计算机动画,难以模拟真实人物的动作神态等,容易引发恐怖谷效应。

    Ar-Sr-Na
    渲染GitHubGit开源
  • Cloudreve添加腾讯云对象存储策略教程

    Cloudreve安装好后就可以添加存储策略了,设置文件存储的位置,我将文件存储在腾讯云对象存储,使用腾讯云内容分发进行下载加速和保护源站。

    幻影龙王
    文件存储存储CDN费用中心对象存储
  • 2022年最值得关注的十篇论文,你都看了吗?

    2022 年 1 月,扩散模型第一次吸引了我的眼球。当时我判断到将会有某些大事发生,然而却未曾预料到几个月后会出现什么:DALLE-2、Imagen、Stable Diffusion 以及其它许多模型。

    一点人工一点智能
    图像处理卷积神经网络自然语言处理自然语言深度学习
  • ECCV 2022 | 基于点云累积的动态三维场景分析

    标题:Dynamic 3D Scene Analysis by Point Cloud Accumulation

    一点人工一点智能
    点云建模人工智能图像分析
  • 工作流引擎架构设计

    最近开发的安全管理平台新增了很多工单申请流程需求,比如加白申请,开通申请等等。最开始的两个需求,为了方便,也没多想,就直接开发了对应的业务代码。

    AlwaysBeta
    开源AngularJShttps网络安全架构设计
  • Golang如何实现节假日不打扰用户?

    这里我们利用下json转golang struct的小工具,把接口返回的json转成golang的代码

    壮壮熊
    Go
  • 【N32G457】基于N32G457和RT-Thread全新打造的私有化定制家用式智能告警系统(2022年国民技术MCU&RT-Thread设计大赛第一名作品)

    近些年来,随着科技的更新迭代,IoT行业迎来了一个快速膨胀发展的窗口期,我们随之可见的是,越来越多的智能化产品进入到了我们的日常生活中,包括发展比较早的智能家居类产品、智能家电类产品,还有近些年非常火热的智能穿戴类产品,这些都得到了市场很好的反馈。

    架构师李肯
    微信企业物联网单片机系统架构

扫码关注腾讯云开发者

领取腾讯云代金券