hexo-redefine 部署指南(持续更新)

hexo-redefine 部署指南(持续更新)

Lucas Lv1

所有的标题对应的功能都可以点击跳转到对应的 redefine 官方文档

npm 包相关安装设置

搜索文章

安装:

1
npm install hexo-generator-searchdb

_config.redefine.yml 相关设置

1
2
3
search:
enable: true // 开关 默认 false
preload: true // 预加载 默认 true

文章推荐

nodejieba 通过对文章内容进行中文分词并计算文章之间的关键词相似度,根据相似度排序,在 Hexo 页面底部自动推荐与当前文章主题最接近的历史文章。

安装:

1
npm install nodejieba@latest

_config.redefine.yml 相关设置

1
2
3
4
5
6
7
recommendation:
enable: true
title: 其他文章
limit: 3
mobile_limit: 2
placeholder: /images/wallhaven-wqery6-light.webp
skip_dirs: []

字数统计

1
npm install hexo-wordcount

_config.redefine.yml 相关设置

1
2
3
4
word_count:
enable: true # Whether to enable
count: true # Whether to display word count
min2read: true # Whether to display reading time

katex 来写 math(官方文档没有)

个人感觉会比 mathjax 更快更稳定

安装:

1
2
npm uninstall hexo-renderer-marked
npm install hexo-renderer-markdown-it @iktakahiro/markdown-it-katex

_config.yml 相关配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# render-Markdown-it
# Markdown-it config
markdown:
render:
html: true
xhtmlOut: false
breaks: true
linkify: true
typographer: true
quotes: '“”‘’'
plugins:
- name: "@iktakahiro/markdown-it-katex"
options:
strict: false

新建 source/css/katex.css 文件,粘贴(后面的自定义样式补丁可以不粘贴, 只粘贴 @import 那一行就行):

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
/* ==============================
引入外部样式 (Katex)
============================== */
@import url('https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css');

/* ==============================
自定义样式补丁
============================== */
.light-mode {
--katex-background-color: #f1f1f1;
}

.dark-mode {
--katex-background-color: #313131;
}

/* # 公式边框 美化要不太丑了 */
.katex-block {
overflow-x: auto !important;
border-radius: 6px !important;
padding-left: 12px !important;
padding-right: 12px !important;
width: fit-content !important;
max-width: 100% !important;
border: 1px dashed !important;
background-color: var(--katex-background-color) !important;
}

.katex {
font-size: 1em !important;
}

:not(.katex-display) > .katex {
border-radius: 4px !important;
padding: 4px !important;
border: 1px dotted !important;
background-color: var(--katex-background-color) !important;
}

_config.redefine.yml 相关设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# INJECT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> start
# Docs: https://redefine-docs.ohevan.com/inject
inject:
# Whether to enable inject
enable: true
# Inject custom head html code
head:
- "<style> @import url('/css/katex.css') </style>"

# Inject custom footer html code
footer:
-
-
# INJECT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< end

hexo 官方配置

图片引入

1
![image](image.jpg)

image

如果你的渲染器是 hexo-renderer-markdown-it,修改如下内容:

1
post_asset_folder: true

如果你的渲染器是 hexo-renderer-marked
搜索 post_asset_folder ,改成 true ,然后添加

1
2
3
4
post_asset_folder: true
marked:
prependRoot: true
postAsset: true

如果没有,那就在自己添加一下,但我强烈建议你使用 hexo-renderer-markdown-it

启用后,资源图片将会被自动解析为其对应文章的路径。
例如:image.jpg 位置为 /2020/01/02/foo/image.jpg,这表示它是 /2020/01/02/foo/ 文章的一张资源图片, ![](image.jpg) 将会被解析为 <img src="/2020/01/02/foo/image.jpg">

另外,hexo 并不能完美在你修改之后进行 html 的实时渲染,尤其是你修改了配置文件。
在渲染出错的时候,可以直接进入本地的 public/ 里查看实际生成的内容。

类标签适配

有时候在跳转到某个标签下的文章的时候,会出现忽略特殊字符的情况,比如 C++ 识别为 C 导致 C++ 标签的文章和 C 标签的文章被错误地归为一类,所以可以在 _config.yml 里添加或者修改 tag_map 字段:

_config.yml 相关设置

1
2
3
4
5
default_category: uncategorized
category_map:
tag_map:
'C++': cpp
'C#': c-sharp

这样,路径就会这样显示 http://127.0.0.1:4000/tags/cpp/ http://127.0.0.1:4000/tags/c-sharp/

个人使用习惯

开始使用 codespaces

我总感觉配置博客是一个很麻烦的事情,如果能配置一次以后不需要大调整就最好了,所以我就把博客系统托管了,考虑买个 VPS 的,但又感觉有点贵,最后选择了 github 的 codespaces ,弊端是限制时间,优点是写博客不需要耗太多时间,只需要将博客在本地写好,然后再在 codespaces 调整一下格式然后提交就行。

这也是我最关心的,写博客只关注博客本身就好了,频繁修改格式会打扰思路,这样将写内容和调整格式,反而可以更顺畅的来写博客

codespaces 部署的方便快捷

codespaces 天然有 github 的权限

我是在一个 blog 仓库里向 DarkFlameMasterDev.github.io 部署博客

所以就需要跨仓库的权限,只需要执行以下命令即可

1
2
3
4
5
6
gh auth logout
unset GITHUB_TOKEN
gh auth login
> GitHub.com
> HTTPS
> Login with a web browser

授予它权限即可。

最后将 _config.yml 进行修改

1
2
3
4
5
6
# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: git
repo: https://github.com/DarkFlameMasterDev/DarkFlameMasterDev.github.io.git
branch: main
  • 标题: hexo-redefine 部署指南(持续更新)
  • 作者: Lucas
  • 创建于 : 2026-08-14 23:12:51
  • 更新于 : 2026-08-22 02:14:32
  • 链接: https://darkflamemasterdev.github.io/2026/08/14/hexo-redefine-部署指南(持续更新)/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论