一、安装主题

1. Git安裝

1.1 在博客根目录里安装最新版主题
anzhiyu主题:

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

butterfly主题:

1
git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly

1.2. 第一次使用需要安装 pug 以及 stylus 的渲染器

1
npm install hexo-renderer-pug hexo-renderer-stylus --save

2. 应用主题

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

1
theme: anzhiyu

3. 覆盖配置

覆盖配置可以使主题配置放置在anzhiyu或butterfly目录之外,避免在更新主题时丢失自定义的配置。

如果你是linux系统就执行以下命令:

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

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

如果你是windows系统就请手动将/themes/anzhiyu/_config.yml(/themes/butterfly/_config.yml)复制到根目录下并重命名为_config.butterfly.yml即可。

以后如果修改任何主题配置,都只需修改 _config.anzhiyu.yml(_config.butterfly.yml) 的配置即可。
也可以用cmd

1
copy "themes\butterfly\_config.yml" "_config.butterfly.yml"

4. 基础配置

Hexo 全局配置文件:_config.yml
官方文档:https://hexo.io/zh-cn/docs/configuration

Butterfly 主题配置文件:_config.butterfly.yml
官方文档:https://butterfly.js.org

注意:

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

5. 配置主题与主站配置文件

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

本地预览

1
hexo cl; hexo s

推送更新

1
hexo cl; hexo g; hexo d

二、主要配置

1. 生成标签页

  • 执行以下命令生成标签页
1
hexo new page tags
  • 找到 source/tags/index.md 这个文件,修改添加 type: “tags”
1
2
3
4
5
6
7
---
title: 标签
date: 2025-07-05 03:36:02
type: "tags"
comments: false
top_img: false
---

2. 生成分类页

  • 执行以下命令生成分类页
1
hexo new page categories
  • 找到 source/categories/index.md 这个文件,修改添加 type: “categories”
1
2
3
4
5
6
7
---
title: 分类
date: 2025-07-05 03:36:48
aside: false
top_img: false
type: "categories"
---

剩下的工作就是配置_config.yml和_config.anzhiyu.yml文件,修改博客参数。

3. 配置文章模版

/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: # 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模版,仅供参考
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
    npm install hexo-generator-topindex --save
    • 设置置顶

    给需要置顶的文章加入top参数,如下:

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

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

  • 开启本地搜索

    你需要安装 hexo-generator-search,根据它的文档去做相应配置

    1
    npm install hexo-generator-search --save

    设置主题配置文件

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

四、 添加全屏模式

1. 在source/css文件夹下新建custom.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* =================================================== */
/* == 最终版 - 仅控制宽度,不影响侧边栏 == */
/* =================================================== */


/* 这些样式只在 body 标签有一个叫 .fullscreen-mode 的 class 时才会生效 */


/* --- Part 1: 针对【文章页面】的全屏样式 --- */

/* 定位到文章页最外层容器 .post,并让其撑满 */
body.fullscreen-mode .post #body-wrap,
body.fullscreen-mode .post #content-inner,
body.fullscreen-mode .post #post {
width: 100vw !important;
max-width: none !important;
padding: 0 !important;
margin: 0 !important;
}

/* 移除文章内容的宽度限制 */
body.fullscreen-mode .post #article-container.container {
max-width: none !important;
padding: 20px 40px !important; /* 给左右留一点点边距,防止文字贴边 */
}

/* 隐藏文章页顶部大图和底部版权区,以获得更好全屏效果 */
body.fullscreen-mode .post #header,
body.fullscreen-mode .post #footer {
display: none !important;
}


/* --- Part 2: 针对【主页】文章列表的全屏样式 --- */

/* 定位到主页最外层容器 .page,并移除其宽度限制 */
body.fullscreen-mode .page #content-inner {
width: 100vw !important;
max-width: none !important;
padding: 0 !important;
margin: 0 !important;
}

/* 给主页的文章卡片列表区域加一点边距,防止卡片贴边 */
body.fullscreen-mode .page #recent-posts {
padding: 40px !important;
}
/* =================================================== */
/* == Part 3: 移动端适配 (响应式设计) == */
/* =================================================== */

@media screen and (max-width: 768px) {
/* 上面的 @media screen and (max-width: 768px) 的意思是:
“如果屏幕宽度小于或等于 768px (典型的平板和手机宽度),
就执行花括号 { } 里的所有样式。”
*/

/* 在手机上,减小文章页的左右边距 */
body.fullscreen-mode .post #article-container.container {
padding: 20px 15px !important; /* 左右边距从 40px 大幅减小到 15px */
}

/* 在手机上,减小主页文章列表的左右边距 */
body.fullscreen-mode .page #recent-posts {
padding: 20px 15px !important; /* 左右边距从 40px 大幅减小到 15px */
}
}

2. 在source/js文件夹下新建mode-switcher.js文件,添加内容:

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
// IIFE to avoid polluting global scope
(function() {
// Wait for the DOM to be fully loaded
document.addEventListener('DOMContentLoaded', function() {
const CLASS_NAME = 'fullscreen-mode';
const STORAGE_KEY = 'theme_fullscreen_mode';
const BUTTON_ID = 'fullscreen-toggle-btn';

// Find the container for the button
const rightsideConfig = document.getElementById('rightside-config-hide');

// If the container doesn't exist, do nothing
if (!rightsideConfig) {
return;
}

// --- 1. Create the button ---
const button = document.createElement('button');
button.id = BUTTON_ID;
button.type = 'button';
button.title = '切换全屏模式';
button.innerHTML = '<i class="fas fa-expand"></i>';

// Add the button to the page
rightsideConfig.appendChild(button);

// --- 2. Function to apply the mode ---
const applyMode = (isFullScreen) => {
if (isFullScreen) {
document.body.classList.add(CLASS_NAME);
button.innerHTML = '<i class="fas fa-compress"></i>'; // Change icon to "compress"
} else {
document.body.classList.remove(CLASS_NAME);
button.innerHTML = '<i class="fas fa-expand"></i>'; // Change icon to "expand"
}
};

// --- 3. Add click event listener to the button ---
button.addEventListener('click', () => {
const isCurrentlyFullScreen = document.body.classList.contains(CLASS_NAME);
// Toggle the mode and save the new state
applyMode(!isCurrentlyFullScreen);
localStorage.setItem(STORAGE_KEY, !isCurrentlyFullScreen);
});

// --- 4. Check localStorage on page load and apply the saved mode ---
const savedMode = localStorage.getItem(STORAGE_KEY);
// If savedMode is 'true', apply fullscreen, otherwise default to not fullscreen
applyMode(savedMode === 'true');
});
})();

3. 修改_config.butterfly.yml

1
2
3
4
5
inject:
head:
- <link rel="stylesheet" href="/css/custom.css">
bottom:
- <script src="/js/mode-switcher.js"></script>

配置完成后在右下角的控制按钮里多了一个全屏切换。