Hexo博客美化教程 - AnZhiYu主题配置
在上一篇文章中,我们介绍了如何搭建一个基础的Hexo博客。今天,我将为大家带来AnZhiYu主题的安装和配置教程。AnZhiYu是一款美观、功能丰富的Hexo主题,通过本教程,你将能够让你的博客焕然一新,拥有更加个性化的外观和功能。
1. 安装安知鱼主题
1.1. Git 安装
在博客根目录执行以下命令安装最新版主题:
1
| git clone -b main https://github.com/anzhiyu-c/hexo-theme-anzhiyu.git themes/anzhiyu
|
第一次使用需要安装 pug 以及 stylus 的渲染器:
1
| npm install hexo-renderer-pug hexo-renderer-stylus --save
|
1.2. 应用主题
修改 hexo 配置文件_config.yml
,把主题改为anzhiyu
:
1.3. 覆盖配置
覆盖配置可以使主题配置
放置在 anzhiyu 目录之外,避免在更新主题时丢失自定义的配置。
Linux系统执行以下命令:
1
| cp -rf ./themes/anzhiyu/_config.yml ./_config.anzhiyu.yml
|
Windows系统手动将/themes/anzhiyu/_config.yml
复制到根目录下并重命名为_config.anzhiyu.yml
,或使用以下命令:
1 2
| cp themes/anzhiyu/_config.yml _config.anzhiyu.yml
|
注意事项:
- 只要存在于
_config.anzhiyu.yml
的配置都是高优先级,修改原 _config.yml
是无效的
- 每次更新主题可能存在配置变更,请注意更新说明
- 可通过
hexo g --debug
查看覆盖配置是否生效
- 如果想将某些配置覆盖为空,不要把主键删掉,否则无法覆盖
1.4. 本地预览与部署
1 2 3 4 5
| hexo cl; hexo s
hexo cl; hexo g; hexo d
|
1.5. 生成标签页和分类页
生成标签页:
修改 source/tags/index.md
:
1 2 3 4 5 6 7
| --- title: 标签 date: 2025-07-21 12:00:00 type: "tags" comments: false top_img: false ---
|
生成分类页:
1
| hexo new page categories
|
修改 source/categories/index.md
:
1 2 3 4 5 6 7
| --- title: 分类 date: 2025-07-21 12:00:00 type: "categories" comments: false top_img: false ---
|
2. 配置文章模版
2.1. post.md模版参考
在scaffolds/post.md
中配置以下内容:
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| --- title: {{ title }} date: {{ date }} updated: tags: categories: keywords: description: top: top_img: comments: cover: https://img.090227.xyz/file/ae62475a131f3734a201c.png toc: toc_number: toc_style_simple: copyright: copyright_author: copyright_author_href: copyright_url: copyright_info: mathjax: katex: aplayer: highlight_shrink: aside: swiper_index: 10 top_group_index: 10 ai: background: "#fff" ---
<div class="video-container"> [up主专用,视频内嵌代码贴在这] </div>
<style> .video-container { position: relative; width: 100%; padding-top: 56.25%; /* 16:9 aspect ratio (height/width = 9/16 * 100%) */ }
.video-container iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } </style>
|
2.2. page.md模版参考
在scaffolds/page.md
中配置以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| --- title: {{ title }} date: {{ date }} type: updated: comments: description: keywords: top_img: https://img.090227.xyz/file/ae62475a131f3734a201c.png mathjax: katex: aside: aplayer: highlight_shrink: top_single_background: ---
|
3. 主题基本配置
3.1. 菜单配置
菜单配置决定了网站顶部的导航栏内容,可以根据自己的需求进行调整:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| menu: 文章: 隧道: /archives/ || anzhiyu-icon-box-archive 分类: /categories/ || anzhiyu-icon-shapes 标签: /tags/ || anzhiyu-icon-tags 友链: 友人帐: /link/ || anzhiyu-icon-link 朋友圈: /fcircle/ || anzhiyu-icon-artstation 留言板: /comments/ || anzhiyu-icon-envelope 我的: 音乐馆: /music/ || anzhiyu-icon-music 相册集: /album/ || anzhiyu-icon-images 小空调: /air-conditioner/ || anzhiyu-icon-fan 关于: 关于本人: /about/ || anzhiyu-icon-paper-plane 闲言碎语: /essay/ || anzhiyu-icon-lightbulb 随便逛逛: javascript:toRandomPost() || anzhiyu-icon-shoe-prints1
|
格式为:页面名称: 链接地址 || 图标
,其中图标使用的是AnZhiYu主题内置的图标库。
3.2. 社交链接配置
在侧边栏展示你的社交媒体链接:
1 2 3 4 5 6
| social: Github: https://github.com/你的用户名 || anzhiyu-icon-github BiliBili: https://space.bilibili.com/你的ID || anzhiyu-icon-bilibili QQ: tencent://Message/?Uin=你的QQ号 || anzhiyu-icon-qq 微博: https://weibo.com/你的用户名 || anzhiyu-icon-weibo 知乎: https://www.zhihu.com/people/你的ID || anzhiyu-icon-zhihu
|
3.3. 头像配置
设置你的个人头像:
1 2 3
| avatar: img: /img/avatar/Avatar.jpg effect: true
|
3.4. 首页封面配置
配置首页顶部的封面图片和标题:
1 2 3 4 5
| banner: tips: 个人博客 title: 我的博客标题 image: /img/4CB4B9060DB50206C98341C4CD589637.jpg link: /
|
3.5. 网站图标配置
设置网站的favicon图标:
4. 更多功能配置
4.1. 新建文章
新建博文命令:
新建标签页命令:
4.2. 文章置顶
安装插件:
1 2
| npm uninstall hexo-generator-index --save npm install hexo-generator-index-pin-top --save
|
设置置顶,在文章Front-matter中添加:
1 2 3 4
| --- title: 文章标题 top: 1 ---
|
4.3. 开启本地搜索
安装插件:
1
| npm install hexo-generator-searchdb --save
|
在站点配置文件_config.yml
中添加:
1 2 3 4 5
| search: path: search.xml field: post content: true format: html
|
在主题配置文件_config.anzhiyu.yml
中设置:
1 2 3 4
| local_search: enable: true preload: false CDN:
|
参数说明:
- enable: 是否开启本地搜索
- preload: 预加载,开启后进入网页会自动加载搜索文件
- CDN: 搜索文件的CDN地址(默认使用本地链接)
4.4. 添加任意文件
如需在网站根目录添加文件(如ads.txt
),只需在/source
文件夹下放置该文件即可。
5. 进阶配置
5.1. 自定义样式
如果你想添加自定义CSS,可以在source/css
目录下创建custom.css
文件,然后在_config.anzhiyu.yml
中引入:
1 2 3
| inject: head: - <link rel="stylesheet" href="/css/custom.css" media="defer" onload="this.media='all'">
|
5.2. 自定义脚本
同样,你可以添加自定义JavaScript:
1 2 3
| inject: bottom: - <script src="/js/custom.js"></script>
|
5.3. PWA支持
配置渐进式Web应用(PWA)支持:
1 2 3 4 5 6 7 8 9
| pwa: enable: true manifest: /manifest.json theme_color: var(--anzhiyu-main) mask_icon: /img/siteicon/apple-icon-180.png apple_touch_icon: /img/siteicon/apple-icon-180.png bookmark_icon: /img/siteicon/apple-icon-180.png favicon_32_32: /img/siteicon/32.png favicon_16_16: /img/siteicon/16.png
|
5.4. 图片懒加载
配置图片懒加载以提高页面加载速度:
1 2 3 4 5
| lazyload: enable: true field: site placeholder: blur: true
|
5.5. 页面特效
配置各种页面特效:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| fireworks: enable: true zIndex: 9999 mobile: false
activate_power_mode: enable: true colorful: true shake: true mobile: false
runtimeshow: enable: true publish_date: 07/20/2023 00:00:00
darkmode: enable: true button: true autoChangeMode: 1
|
6. 常见问题解决
6.1. 图片路径问题
在AnZhiYu主题中,图片可以放在以下位置:
- 站点图片:放在
source/img/
目录下
- 文章图片:可以放在
source/img/post/文章名/
目录下,或者使用相对路径
6.2. 主题更新问题
更新AnZhiYu主题时,可以使用以下命令:
然后重新生成和部署网站。
6.3. 自定义页面问题
如果你想创建自定义页面(如友链页面),可以使用以下命令:
然后编辑source/link/index.md
文件,添加以下内容:
1 2 3 4 5
| --- title: 友情链接 date: 2025-07-21 12:00:00 type: "link" ---
|
7. 主题美化技巧
7.1. 添加网站动画
AnZhiYu主题支持多种网站动画效果,可以在配置文件中启用:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| canvas_ribbon: enable: true size: 150 alpha: 0.6 zIndex: -1 click_to_change: false mobile: false
canvas_fluttering_ribbon: enable: true mobile: false
canvas_nest: enable: true color: "0,0,255" opacity: 0.7 zIndex: -1 count: 99 mobile: false
|
7.2. 自定义鼠标样式
可以通过CSS自定义鼠标指针样式:
1 2 3 4 5 6 7 8
| body { cursor: url('/img/cursor/normal.cur'), auto; }
a, button, .button, #article-container a.btn, input[type="button"], input[type="reset"], input[type="submit"] { cursor: url('/img/cursor/pointer.cur'), auto !important; }
|
然后将自定义鼠标图标放在source/img/cursor/
目录下。
7.3. 添加网站背景
设置网站背景图片:
1 2 3 4
| background: url: /img/background.jpg opacity: 1
|
8. 参考资源
9. 总结
通过本教程,我们详细介绍了AnZhiYu主题的安装和配置方法。从基本配置到进阶设置,每一步都有详细的说明和示例。通过这些配置,你可以打造一个独具个性的博客网站。
AnZhiYu主题功能丰富,配置灵活,适合各种类型的个人博客。希望这篇教程能帮助你顺利配置出一个美观、实用的个人博客!
如果你在配置过程中遇到任何问题,欢迎在评论区留言讨论。祝你的博客之旅愉快!