描述

butterfly默认使用cdn是JsDelivr ,DNS被污染还有各种原因,这个cdn不好用了,导致我的网站样式加载卡顿甚至加载不出来。

butterfly:2023-07-07 稳定版4.9.0

步骤

第一步:更改本地yml配置

上网查了一下解决方法——资源本地化,即把需要的CSS、JS文件下载下来。资源包使用npm管理下载,_config.butterfly.yml文件相关代码段如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
CDN:
# The CDN provider of internal scripts (主題內部 js 的 cdn 配置)
# option: local/jsdelivr/unpkg/cdnjs/custom
# Dev version can only choose. ( dev版的主題只能設置為 local )
internal_provider: local

# The CDN provider of third party scripts (第三方 js 的 cdn 配置)
# option: local/jsdelivr/unpkg/cdnjs/custom
# when set it to local, you need to install hexo-butterfly-extjs
# third_party_provider: jsdelivr
third_party_provider: local

# Add version number to url, true or false
version: false

# Custom format
# For example: https://cdn.staticfile.org/${cdnjs_name}/${version}/${min_cdnjs_file}
custom_format:

option:
# main_css:
# main:
# utils:
# translate:

third_party_provider默认是JsDelivr,这里更改为local

第二步:下载资源包

1
npm install hexo-butterfly-extjs

提示:

这里可以更改一下镜像源,避免下载过慢

先查看一下所用的源:

1
npm get registry

发现是官方源https://registry.npmjs.org/,官方源比较不会报错,如果太慢可以换一个

1
npm config set registry https://registry.npm.taobao.org

第三步:复制资源包到相应目录

按照_config.butterfly.ymCDN代码方面的注释,到第二步就可以了,但是运行hexo clean & hexo g时报错,说找不到disqusjs/dist/browser/styles/disqusjs.css和disqusjsdist/browser/disqusjs.es2015.umd.min.js这两个文件。

换个思路解决问题

查找其他css/js文件的位置,找出为什么其它文件没问题

hexo.yml文件如下:

1
2
3
4
disqusjs_css:
name: disqusjs
file: dist/browser/styles/disqusjs.css
version: 3.0.2
1
2
3
4
twikoo:
name: twikoo
file: dist/twikoo.all.min.js
version: 1.6.16

用everything查找,发现twikoo文件夹在hexo_modules,而这个目录里却没有disqusjs文件夹。查找一下这个文件夹,位置在hexo_modules-butterfly-extjs_modules。复制一份到这里,解决问题

其他说明

hexo_modules-butterfly-extjs和hexo.yml文件,起作用的是后者。