hexo

Hexo博客美化

2026-05-15 #hexo

〖Hexo博客系列〗No.2 美化Hexo博客,教你如何安装和美化Hexo博客

原文:CMLiussss Blog HexoBlogNo2

美化Hexo博客,主题安装配置

这期教程演示将使用一款基于 hexo-theme-butterfly 修改的主题 —— 安知鱼(AnZhiYu)。


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

1
theme: anzhiyu

1.3 覆盖配置

Linux:

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

Windows:

手动复制:

1
/themes/anzhiyu/_config.yml

到根目录并重命名为:

1
_config.anzhiyu.yml

说明:

  • 修改主题配置时,只需修改 _config.anzhiyu.yml
  • _config.anzhiyu.yml 优先级高于 _config.yml
  • 更新主题后需要同步配置
  • 可使用 hexo g --debug 检查覆盖配置是否生效

1.4 本地预览与部署

本地预览

1
2
hexo cl
hexo s

推送上线

1
2
3
hexo cl
hexo g
hexo d

1.5 生成标签页和分类页

生成标签页

1
hexo new page tags

编辑:

1
source/tags/index.md

内容:

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

编辑:

1
source/categories/index.md

内容:

1
2
3
4
5
6
7
---
title: 分类
date: 2024-07-05 03:36:48
aside: false
top_img: false
type: "categories"
---

2. 配置文章模板

/scaffolds 目录下:

  • post.md:文章模板
  • page.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:
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%;
}

.video-container iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
</style>

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:
description:
keywords:
top_img: https://img.090227.xyz/file/ae62475a131f3734a201c.png
mathjax:
katex:
aside:
aplayer:
highlight_shrink:
top_single_background:
---

更多功能

新建文章

新建博文

1
hexo new 这是一篇新的博文

新建标签页

1
hexo new page 新建的标签页

文章置顶

安装插件

1
npm install hexo-generator-topindex --save

设置置顶

文章 Front Matter:

1
2
3
4
5
6
7
8
9
---
title: 每天一个linux命令
date: 2017-01-23 11:41:48
top: 1
categories:
- 运维
tags:
- linux命令
---

多个置顶文章时:

  • top 数值越大越靠前

开启本地搜索

安装插件

1
npm install hexo-generator-search --save

配置主题

1
2
3
4
local_search:
enable: true
preload: false
CDN:

参数说明:

参数 说明
enable 是否开启本地搜索
preload 是否预加载搜索文件
CDN 搜索文件 CDN 地址

添加任意文件

例如:

如果想在网站根目录添加 ads.txt

只需放到:

1
/source

目录下即可。


参考资料

评论
分享