Hexo博客美化-AnZhiYu(安知鱼)主题安装及个性化配置


AnZhiYu(安知鱼)主题 是基于hexo-theme-butterfly修改的hexo主题,支持多种功能和自定义选项,兼具美观与功能性;特别适合对个性化设计和功能拓展有较高需求的博客用户。其强大的自定义能力、SEO 友好的设计,使其成为Hexo主题中的佼佼者。如果您是Hexo用户,并且正在寻找一款现代化、功能丰富且高度可自定义的主题,AnZhiYu主题 无疑是一个非常好的选择。

项目地址https://github.com/anzhiyu-c/hexo-theme-anzhiyu
官方文档https://docs.anheyu.com/initall.html

[]

一、安装应用主题

1、通过 Git 安裝主题

在博客根目录里安装最新版AnZhiYu主题,项目地址:https://github.com/anzhiyu-c/hexo-theme-anzhiyu

[!tip]
推荐使用Visual Studio Code代码编辑器终端执行代码,这样不用在Git BashWindows文件管理器之间来回切换。

1
git clone -b main https://github.com/anzhiyu-c/hexo-theme-anzhiyu.git themes/anzhiyu

第一次使用AnZhiYu主题 需要安装pug以及stylus的渲染器,安装代码如下:

1
git clone -b main https://github.com/anzhiyu-c/hexo-theme-anzhiyu.git themes/anzhiyu

2、应用主题

修改 hexo 配置文件_config.yml,把主题改为anzhiyu

1
theme: anzhiyu

3、覆盖配置

覆盖配置可以使主题配置放置在anzhiyu目录之外,避免在更新主题时丢失自定义的配置。
如果是linux系统执行以下命令

1
cp -rf ./themes/anzhiyu/_config.yml ./_config.anzhiyu.yml

如果是windows系统就请手动将/themes/anzhiyu/_config.yml复制到根目录下并重命名为_config.anzhiyu.yml即可。
以后如果修改任何主题配置,都只需修改_config.anzhiyu.yml的配置即可。

[!caution]

  • 只要存在于_config.anzhiyu.yml的配置都是高优先级,修改原_config.yml是无效的。
  • 每次更新主题可能存在配置变更,请注意更新说明,可能需要手动对_config.anzhiyu.yml同步修改。
  • 想查看覆盖配置有没有生效,可以通过hexo g --debug查看命令行输出。
  • 如果想将某些配置覆盖为空,注意不要把主键删掉,不然是无法覆盖的

4、配置主题与主站配置文件

到这一步主题部署就完成了,就是这么简单!!!

本地预览命令

1
hexo cl; hexo s

推送更新上线命令

1
hexo cl; hexo g; hexo d

5、生成标签页和分类页

  • 执行以下命令生成 标签页
    1
    hexo new page tags
    找到source/tags/index.md这个文件,修改添加type: "tags"
    1
    2
    3
    4
    5
    6
    7
    ---
    title: 标签
    date: 2024-07-05 03:36:02
    type: "tags"
    comments: false
    top_img: false
    ---
  • 执行以下命令生成分类页
    1
    hexo new page categories
    找到source/categories/index.md这个文件,修改添加type: "categories"
    1
    2
    3
    4
    5
    6
    7
    ---
    title: 分类
    date: 2024-07-05 03:36:48
    aside: false
    top_img: false
    type: "categories"
    ---
    剩下的工作就是配置_config.yml_config.anzhiyu.yml文件,修改博客参数。详细配置参数介绍参见anzhiyu主题官方文档https://docs.anheyu.com/initall.html

二、配置文章模版

/scaffolds目录下有几个模版文件,其中

  • post.md:新建博文模版
  • page.md:新建页面模版

post.md模版,仅供参考

下面为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
---
title: {{ title }} #【必需】页面标题
date: {{ date }} #【必需】页面创建日期
updated: #【可选】页面更新日期
tags: #【可选】文章标签
categories: #【可选】文章分类
keywords: #【可选】文章关键字
description: #【可选】文章描述
top: # 1 置顶
top_img: #【可选】文章顶部图片
comments: #【可选】显示文章评论模块(默认 true)
cover: https://img.090227.xyz/file/ae62475a131f3734a201c.png #【可选】文章缩略图(如果没有设置 top_img,文章页顶部将显示缩略图,可设为 false/图片地址/留空)
toc: #【可选】显示文章 TOC(默认为设置中 toc 的 enable 配置)
toc_number: #【可选】显示 toc_number(默认为设置中 toc 的 number 配置)
toc_style_simple: #【可选】显示 toc 简洁模式
copyright: #【可选】显示文章版权模块(默认为设置中 post_copyright 的 enable 配置)
copyright_author: #【可选】文章版权模块的文章作者
copyright_author_href: #【可选】文章版权模块的文章作者链接
copyright_url: #【可选】文章版权模块的文章作者链接
copyright_info: #【可选】文章版权模块的版权声明文字
mathjax: #【可选】显示 mathjax(当设置 mathjax 的 per_page: false 时,才需要配置,默认 false)
katex: #【可选】显示 katex(当设置 katex 的 per_page: false 时,才需要配置,默认 false)
aplayer: #【可选】在需要的页面加载 aplayer 的 js 和 css,请参考文章下面的音乐 配置
highlight_shrink: #【可选】配置代码框是否展开(true/false)(默认为设置中 highlight_shrink 的配置)
aside: #【可选】显示侧边栏 (默认 true)
swiper_index: 10 #【可选】首页轮播图配置 index 索引,数字越小越靠前
top_group_index: 10 #【可选】首页右侧卡片组配置, 数字越小越靠前
ai: #【可选】文章ai摘要
background: "#fff" #【可选】文章主色,必须是16进制颜色且有6位,不可缩减,例如#ffffff 不可写成#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>

page.md模版,仅供参考

下面为page.md模板内完整参数解释,可根据需要删减不需要的参数文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
---
title: {{ title }} #【必需】页面标题
date: {{ date }} #【必需】页面创建日期
type: #【必需】标签、分类、关于、音乐馆、友情链接、相册、相册详情、朋友圈、即刻页面需要配置
updated: #【可选】页面更新日期
comments: #【可选】显示页面评论模块(默认 true)
description: #【可选】页面描述
keywords: #【可选】页面关键字
top_img: https://img.090227.xyz/file/ae62475a131f3734a201c.png #【可选】页面顶部图片
mathjax: #【可选】显示 mathjax(当设置 mathjax 的 per_page: false 时,才需要配置,默认 false)
katex: #【可选】显示 katex(当设置 katex 的 per_page: false 时,才需要配置,默认 false)
aside: #【可选】显示侧边栏 (默认 true)
aplayer: #【可选】在需要的页面加载 aplayer 的 js 和 css,请参考文章下面的音乐 配置
highlight_shrink: #【可选】配置代码框是否展开(true/false)(默认为设置中 highlight_shrink 的配置)
top_single_background: #【可选】部分页面的顶部模块背景图片
---

三、更多功能

新建文章

  • 新建博文命令
    1
    hexo new 新的博文标题
  • 新建页面命令
    1
    hexo new page 新建的页面标题

文章置顶

  1. 安装插件
    1
    npm install hexo-generator-topindex --save
  2. 设置置顶
    给需要置顶的文章加入top参数
    1
    2
    3
    4
    5
    6
    7
    8
    9
    ---
    title: 每天一个linux命令
    date: 2017-01-23 11:41:48
    top: 1
    categories:
    - 运维
    tags:
    - linux命令
    ---

    [!info]
    如果存在多个置顶文章,top后的参数越大,越靠前

开启本地搜索

  1. 安装插件
    你需要安装 hexo-generator-search,根据它的文档去做相应配置
    1
    npm install hexo-generator-search --save
  2. 设置本地搜索主题配置文件
    1
    2
    3
    4
    local_search:
    enable: true
    preload: false
    CDN:
    参 数 解 释
    enable 是否开启本地搜索
    preload 预加载,开启后,进入网页后会自动加载搜索文件。关闭时,只有点击搜索按钮后,才会加载搜索文件
    CDN 搜索文件的 CDN 地址(默认使用的本地链接)

添加任意文件

例如当我们想在网站根目录添加ads.txt文件,来通过站长验证时,我们只需要在/source文件夹下放置该文件即可。