安装
前置条件
- Node.js (>=16)
- Git
- Hexo
- 一个可用的 Hexo 博客
如果你还不了解以上内容,请从 Hexo 文档 获取相关帮助。
选择安装方式
两种方式功能等价,按需选择:
| 方式 | 适合人群 | 依赖管理 | 升级方式 |
|---|---|---|---|
| npm 安装(推荐) | 大多数用户 | 自动装齐 | npm install hexo-theme-tranquility@latest |
| Git 克隆 | 需要改源码 / 跟踪主线 | 手动安装 | git pull |
方式一:通过 npm 安装(推荐)
1. 安装主题
运行时依赖(hexo-pagination、moment、opentype.js 等)会随主题自动装齐:
cd hexo
npm install hexo-theme-tranquility
2. 启用主题
配置博客根目录 _config.yml 中的 theme 字段为 tranquility(参考 Themes | Hexo):
theme: tranquility
3. 移除冲突依赖
hexo-generator-category 与 hexo-generator-archive 与本主题的「子页」设计冲突,必须移除(npm 无法自动卸载别的包):
npm uninstall hexo-generator-category hexo-generator-archive
4. 主题配置
在博客根目录新建 _config.tranquility.yml,只需写需要修改的项,其余走包内默认值(Hexo 会深合并覆盖)。
具体配置项查看配置总览,或阅读主题仓库的 _config-template.yml 注释。
方式二:通过 Git 克隆安装
1. 克隆主题仓库
将本仓库克隆到你的 Hexo 目录的 themes/tranquility 文件夹下:
cd hexo
git clone https://github.com/zycwer/hexo-theme-tranquility.git themes/tranquility
2. 启用主题
配置博客根目录 _config.yml 中的 theme 字段为 tranquility(参考 Themes | Hexo):
theme: tranquility
3. 移除冲突依赖并安装必要依赖
npm uninstall hexo-generator-category hexo-generator-archive
npm install hexo-pagination moment opentype.js
hexo-generator-category 与 hexo-generator-archive 与本主题的「子页」设计冲突,必须移除。
4. 主题配置
将主题目录下的配置文件 themes/tranquility/_config-template.yml 复制到博客根目录下,并重命名为 _config.tranquility.yml:
cp themes/tranquility/_config-template.yml _config.tranquility.yml
在 _config.tranquility.yml 中个性化主题配置,具体配置项查看配置总览或阅读配置文件的注释。
验证
hexo clean && hexo s
浏览器访问 http://localhost:4000,看到主题首页即安装成功。
报错排查
阅读报错可以更快地定位问题。
缺少依赖
随着主题的更新可能会依赖更多的第三方模块,此时用户需要自己添加新的依赖。例如,运行报错内容如下:
...
Error: Cannot find module 'a_third_module'
...
显然根据提示,缺少名为 a_third_module 的模块,安装该依赖即可:
npm install a_third_module