本文最后更新于 2025年2月22日 上午
实现方法
Fluid提供了「自定义 JS / CSS / HTML」的方式,如果你想引入外部的 JS、CSS(比如 IconFont)或 HTML,可以通过以下主题配置,具体见注释:
1 2 3 4 5 6 7 8 9 10 11
| custom_js: /js/custom.js
custom_css: /css/custom.css
custom_head: '<meta name="key" content="value">'
custom_html: '<link rel="stylesheet" href="//at.alicdn.com/t/font_1067060_qzomjdt8bmp.css">'
|
另外 custom_js
和 custom_css
都可以指定多个路径:
1 2 3 4
| custom_css: - /css/macpanel - /css/nav_tittle - /css/custom_fonts
|
具体步骤
-
创建CSS文件
在博客跟目录的 node_modules\hexo-theme-fluid\source\css
或 themes\fluid\source\css
目录下,创建一个custom_fonts.css
(文件名随意)文件,用于设置自定义的字体样式。
-
在CSS中设置自定义字体样式
(我在这里主要使用了「中文网字计划」的朱雀仿宋字体)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
@import url(https://chinese-fonts-cdn.deno.dev/packages/zqfs/dist/ZhuqueFangsong-Regular/result.css);
body, h1, h2, h3, h4, h5, h6, .markdown-body, .navbar, .side-catalog, footer { font-family: "Zhuque Fangsong (technical preview)", KaiTi, "楷体", "楷体_GB2312", STKaiti, "华文楷体", serif !important; }
#subtitle { font-family: "Zhuque Fangsong (technical preview)", serif !important; }
.typed-cursor { font-family: "微软雅黑", "Microsoft YaHei", "宋体", "SimSun", sans-serif !important; }
|
-
启用自定义.css 文件
在Fluid的「主题配置文件」中(一般是在博客根目录下的_config.fluid.yml
或 "node_modules\hexo-theme-fluid\_config.yml"
),启用上面写好的自定义.css 文件:
需要注意一下自定义 .css 文件路径要确保无误
1 2 3
| custom_css: - /css/custom_fonts
|
-
重启博客
完成!