终于弄好了www
经过一天的不懈奋斗,在经过了 jekyll 配置环境的痛苦折磨之后,最后选择了用 hexo + github pages 配置,hexo 是一款静态博客工具,使用起来比较简单,指比让从来没有配过 ruby 的我去弄明白 jekyll 简单多了!
配置方法
- 新建
github仓库,名为<username>.github.io,这个是后来访问用的 - 回到本地命令行(我用的是
wsl)1
2
3
4
5
6npm install -g hexo-cli
sudo npm install -g hexo-cli (Mac) # 据说Mac得这么干
cd AN-EMPTY-FLRODER # 进入你想放置的本地文件夹 一定要是空的!
hexo init # 初始化hexo内容
npm install # 下载配置
npm install hexo-deployer-git --save # 下载部署工具 - 此时环境基本配置完毕了,开始修改配置,打开
_config.yml,将其Deployment部分改为1
2
3
4deploy:
type: git
repository: git@github.com:<username>/<username>.github.io.git
branch: main - 部署准备完成
1
hexo g -d # 生成页面并部署
此时可以访问 https://<username>.github.io 访问自己的博客!
操作方法
1 | hexo new "name" # 新建文章 |
更换主题
进入网站https://hexo.io/themes/可以选择主题,挑选好后进行配置,配置方法为在博客根目录.下执行如下命令:
1 | git clone THEME-REPO themes/<theme-name> |
例如本博客使用的是 stellar 主题,执行命令为:
1 | git clone git@github.com:xaoxuu/hexo-theme-stellar.git themes/stellar |
下载好后,在 ./_config.yml 下修改 theme 的内容为你想要的即可
致谢
https://zhuanlan.zhihu.com/p/60578464
Debug
TypeError: Cannot read properties of null (reading 'utcOffset')- 时区设置错误,允许的中国时区只有
Asia/Harbin,Asia/Shanghai,Asia/Chongqing,Asia/Urumqi,Asia/Kashgar
- 时区设置错误,允许的中国时区只有
- 无法生成
.html文件- 检查
themes下的文件名和配置文件中的是否相同,如果相同尝试先clean再重新创建,如果还是不行则直接重新clone一下主题库(原因未知)
- 检查
- 行内公式无法渲染
- 更换
md渲染器,并添加Katex支持,方法为:并在1
2
3npm un hexo-renderer-marked --save
npm i hexo-renderer-markdown-it --save
npm i @traptitech/markdown-it-katex --save./_config.yml中加入(注意缩进):1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18markdown:
preset: 'default'
render:
html: true
xhtmlOut: true
breaks: true
langPrefix: 'language-'
linkify: true
typographer: true
quotes: '“”‘’'
plugins:
- plugin:
name: '@traptitech/markdown-it-katex'
options: # see https://katex.org/docs/options.html
blockClass: "math-block"
strict: false
throwOnError: false
errorColor: "#cc0000"
- 更换
- 单纯做了上面的操作之后会出现行内数字/字母重复渲染的现象,也即一遍纯文本一遍公式文本,例如 ISP 会被渲染成 ISP
- 在文章头部加上
katex: true即可
- 在文章头部加上
- 静态图片问题
- 使用相对于
./source文件夹的路径,例如/assets/...代表存在./sources/assets/...下,这样在本地 md 显示会有问题,但是 stellar 可以正常生成
- 使用相对于