这一次,经小伙伴提醒,我再次意识到部署在本地的字体文件依旧是我最大的提速障碍。

于是我开始寻求 cdn 服务,也成功让我找到了一家提供免费的服务———中文网字计划。https://chinese-font.netlify.app/zh-cn/

具体操作非常简单,在配置文件 config.butterfly.yml 中找到 inject 模块,在头部插入 css 引用的 link 即可(link 由网站提供)。

1
2
3
4
5
6
inject:
head:
# - <link rel="stylesheet" href="/xxx.css">
# - <link rel="stylesheet" href="/myfont/free_font.css">
- <link rel='stylesheet' href='https://chinese-fonts-cdn.deno.dev/packages/syst/dist/SourceHanSerifCN/result.css'>
bottom:

之后再到 font 部分把加载的字体名称写到最前面,如下:

1
2
3
4
5
6
7
8
9
10
11
font:
global-font-size: 18px
code-font-size:
font-family: Source Han Serif CN VF,free,-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Lato, Roboto, "PingFang SC", "Microsoft JhengHei", "Microsoft YaHei", sans-serif
code-font-family: Source Han Serif CN VF, free,consolas, Menlo, "PingFang SC", "Microsoft JhengHei", "Microsoft YaHei", sans-serif

# Font settings for the site title and site subtitle
# 左上角網站名字 主頁居中網站名字
blog_title_font:
font_link:
font-family: Source Han Serif CN VF, free,Titillium Web, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft JhengHei', 'Microsoft YaHei', sans-serif

其中 free 为本地字体文件,加载时间过长;Source Han Serif CN VF 为 CDN 提供的字体文件,加载时间适中,但偶尔可能出现卡顿。

相比之下,我还是觉得 CDN 的更有性价比,也算是小小的优化了~

而且不得不说,这个字体是真的好看,赏心悦目,让我继续更新博客也充满了动力!