技术 - 使用 hexo 搭建博客

感觉写这个还是比较有必要的。2024.9.17 配置完成的博客,现在作一下经验总结。前人栽树,后人乘凉啊,真是。

前置

  • 安装 Git。https://git-scm.com/
  • 安装 nodejs 新版。https://nodejs.org/en/download/。这里当时以为用 nvm 升级,结果 nvm 只有旧版本,不要用。
  • 安装 Hexo。npm install hexo -g
  • 安装一键部署包。npm install --save hexo-deployer-git

配置 SSH Key

这一段,我是直接参照 https://www.cnblogs.com/chenlove/p/15058170.html(不如说整个流程都是参照它的),直接做即可。

搭建

仍然可以查看上面这一篇,或者查看 Hexo 官方文档 https://hexo.io/zh-cn/docs/setup。整体的逻辑就是用 npm 管理所有的软件包。

编写博客

使用 Markdown。

一般有一个 header,就是在每篇文章的最上方有这样的文字:

1
2
3
4
5
6
7
8
9
---
layout: post
title: ...
date: ...
tags:
- ...
- ...
categories: ...
---

其他是正常的。

about 页的 layout 设置成 about。

外观

为了支持 KaTeX\KaTeX 渲染,使用了 hexo-mathhexo-renderer-markdown-it-plus 插件。

我目前使用的主题是 Fluid,官方文档很全面,整体也很好看。不过有一些细节文档没有提及,在下面贴出我的 _config.fluid.yml(可能不随时更新)。

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: SunsetGlow95's Blog
subtitle: Silently flowing...
description: SunsetGlow95's Blog
keywords:
author: SunsetGlow95
language: zh-CN
timezone: Asia/Shanghai

# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: http://SunsetGlow95.github.io
permalink: :year/:month/:day/:title/
permalink_defaults:
pretty_urls:
trailing_index: true # Set to false to remove trailing 'index.html' from permalinks
trailing_html: true # Set to false to remove trailing '.html' from permalinks

# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:

# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link:
enable: true # Open external links in new tab
field: site # Apply to the whole site
exclude: ''
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
syntax_highlighter: highlight.js
highlight:
enable: true
line_number: true
auto_detect: false
tab_replace: ''
prismjs:
preprocess: true
line_number: true
tab_replace: ''

# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
path: ''
per_page: 10
order_by: -date

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Metadata elements
## https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
meta_generator: true

# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss
## updated_option supports 'mtime', 'date', 'empty'
updated_option: 'mtime'

# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Include / Exclude file(s)
## include:/exclude: options only apply to the 'source/' folder
include:
exclude:
ignore:

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: fluid

# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: git
repository: git@github.com:SunsetGlow95/SunsetGlow95.github.io.git
branch: main

favicon: https://s2.loli.net/2024/10/29/lUILWGcexEiNZjh.png

index:
banner_img: https://s2.loli.net/2024/10/21/iC5uDOy7pe3PzJw.jpg
slogan:
enable: true
text: Randomize.
auto_excerpt:
enable: false

navbar:
blog_title: SunsetGlow95's Blog
menu:
- {
key: 'home',
link: '/',
icon: 'iconfont icon-home-fill',
}
- {
key: 'archive',
link: '/archives/',
icon: 'iconfont icon-archive-fill',
}
- {
key: 'category',
link: '/categories/',
icon: 'iconfont icon-category-fill',
}
- {
key: 'tag',
link: '/tags/',
icon: 'iconfont icon-tags-fill',
}
- {
key: 'links',
link: '/links/',
icon: 'iconfont icon-link-fill',
}
- {
key: 'about',
link: '/about/',
icon: 'iconfont icon-user-fill',
}

archive:
banner_img: https://s2.loli.net/2024/10/21/iC5uDOy7pe3PzJw.jpg

category:
banner_img: https://s2.loli.net/2024/10/21/iC5uDOy7pe3PzJw.jpg

tag:
banner_img: https://s2.loli.net/2024/10/21/iC5uDOy7pe3PzJw.jpg

post:
banner_img: https://s2.loli.net/2024/10/21/iC5uDOy7pe3PzJw.jpg
math:
enable: true
specific: true
engine: katex

links:
banner_img: https://s2.loli.net/2024/10/21/iC5uDOy7pe3PzJw.jpg
items:
- {
title: '洛谷',
avatar: 'https://www.luogu.com.cn/favicon.ico',
link: 'https://www.luogu.com.cn',
}
- {
title: 'Codeforces',
link: 'https://codeforces.com',
}
- {
title: 'AtCoder',
avatar: 'https://atcoder.jp/favicon.ico',
link: 'https://atcoder.jp',
}
- {
title: 'Virtual Judge',
avatar: 'https://vjudge.net/favicon.ico',
link: 'https://vjudge.net',
}
- {
title: 'QOJ',
link: 'https://qoj.ac',
}
- {
title: 'ZROI',
avatar: 'http://zhengruioi.com/pictures/UOJ.png',
link: 'http://zhengruioi.com',
}
- {
title: 'UOJ',
avatar: 'https://uoj.ac/pictures/UOJ.png',
link: 'https://uoj.ac',
}
- {
title: 'LibreOJ',
avatar: 'https://static.cdn.menci.xyz/libreoj-assets/favicon.ico',
link: 'https://loj.ac',
}
- {
title: 'OI Wiki',
avatar: 'https://oi-wiki.org/favicon.ico',
link: 'https://oi-wiki.org',
}
- {
title: 'OIerDb NG',
avatar: 'https://oier.baoshuo.dev/favicon.ico',
link: 'https://oier.baoshuo.dev',
}
- {
title: 'caijianhong - 博客园',
avatar: 'https://cdn.luogu.com.cn/upload/usericon/509229.png',
link: 'https://www.cnblogs.com/caijianhong',
}
- {
title: '菜王的 blog',
avatar: 'https://cdn.luogu.com.cn/upload/usericon/477443.png',
link: 'https://yjh965.github.io',
}

about:
banner_img: https://s2.loli.net/2024/10/21/iC5uDOy7pe3PzJw.jpg
avatar: https://s2.loli.net/2024/10/29/gWdDbIaXM4Lrc53.png
name: "SunsetGlow95"
intro: "Finding myself"
icons:
- {
class: 'iconfont icon-codeforces',
link: 'https://codeforces.com/profile/SunsetGlow95',
tip: 'Codeforces'
}
- {
class: 'iconfont icon-bilibili',
link: 'https://space.bilibili.com/483357008',
tip: 'Bilibili'
}

dark_mode:
enable: true
default: auto

如果在加入 hexo-renderer-markdown-it-plus 后未将 fluid 语言调整为 zh-cn,将会变成德语,但不知道为啥。

我一开始尝试过其他主题,其中觉得比较好看的只有 particlex。但是它不支持 hexo-renderer-markdown-it-plus,代码高亮会死掉。开发者说推荐的渲染器是 hexo-renderer-pandoc,不过我没整成,懒了。

默认主题是 landscape。

维护

以下全部都是工作目录在博客目录下,终端的命令。

  • 清空:hexo clear/hexo cl
  • 生成网页:hexo generate/hexo g。(它是惰性的,如果需要全部刷新需要先执行 hexo cl。)
  • 本地预览:hexo server/hexo s
  • 上传到 GitHub:hexo deploy/hexo d

技术 - 使用 hexo 搭建博客
http://sunsetglow95.github.io/2024/09/27/tech-blog-building/
作者
SunsetGlow95
发布于
2024年9月27日
许可协议