大家的 Hexo 博客都还好吗?

今天用手机访问自己用 Hexo 搭建的博客时,发现加载慢且页面无法正常显示,但是登录电脑访问却又能正常访问,最后使用无痕模式重现了使用手机访问时的问题,打开开发者工具,重新加载页面,发现有几个静态资源无法加载,这些静态资源都是通过 jsDelivr CDN 访问的,访问 jsDeliver 官网也出现了无法正常访问的情况,所以确定问题是由于 jsDeliver 服务不可用导致的。

解决问题

landscape 主题

关闭语法高亮

landscape 主题默认开启了语法高亮的功能,开启此功能会从 jsDeliver 获取 typeface-source-code-pro 的样式文件。

在 _config.yml 中修改如下选项。

1
2
highlight:
enable: false

关闭评论系统

开启 Valine 评论系统会从 jsDeliver 获取 Valine 的 js 文件。

在 _config.landscape.yml 中修改如下选项。

1
2
valine:
enable: false

其它

除了关闭以上功能外,还可以在源码中修改 CDN 供应商或引用本地文件。以上两处引用可在下列文件中找到:

./node_modules/hexo-theme-landscape/layout/_partial/head.ejs
./node_modules/hexo-theme-landscape/layout/_partial/after-footer.ejs

NexT 主题

NexT 主题支持修改 CDN 的供应商选项,可选的值有 local,jsdelivr,unpkg,cdnjs,custom。

在 _config.next.yml 添加或修改 plugins 选项,以下内容可在 ./node_modules/hexo-theme-next/_config.yml 找到。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
vendors:
# The CDN provider of NexT internal scripts.
# Available values: local | jsdelivr | unpkg | cdnjs | custom
# Warning: If you are using the latest master branch of NexT, please set `internal: local`
internal: local
# The default CDN provider of third-party plugins.
# Available values: local | jsdelivr | unpkg | cdnjs | custom
# Dependencies for `plugins: local`: https://github.com/next-theme/plugins
plugins: jsdelivr
# Custom CDN URL
# For example:
# custom_cdn_url: https://cdn.jsdelivr.net/npm/${npm_name}@${version}/${minified}
# custom_cdn_url: https://cdnjs.cloudflare.com/ajax/libs/${cdnjs_name}/${version}/${cdnjs_file}
custom_cdn_url:

使用本地文件

使用本地文件需要先将插件安装到本地。

1
npm install @next-theme/plugins

使用 unpkg 或 cdnjs

默认的 CDN 供应商是 jsdelivr,现在已不可用,可修改为 unpkg 或 cdnjs。

使用自定义的 CDN 链接

使用 BootCDN。

1
2
3
vendors:
plugins: custom
custom_cdn_url: https://cdn.bootcdn.net/ajax/libs/${cdnjs_name}/${version}/${cdnjs_file}

更新 NexT 到最新版本

最新版本的 NexT 已将默认的 CDN 供应商修改为 cdnjs,更新 NexT 亦可解决此问题。

1
npm install hexo-theme-next@latest