安装与部署
环境要求
| 项目 | 要求 |
|---|---|
| Node.js | >= 16.0.0(package.json 中已声明) |
| Hexo | 6 / 7 / 8 均可,Recommended 8.x |
| 渲染器 | hexo-renderer-marked + hexo-renderer-ejs |
安装主题
1 | npm i hexo-theme-xfm |
安装后主题位于 node_modules/hexo-theme-xfm,复制或软链到站点 themes/xfm:
1 | cp -r node_modules/hexo-theme-xfm themes/xfm |
1 | git clone https://github.com/xfm0797/hexo-theme-xfm.git themes/xfm |
跟随仓库最新提交,升级时 git pull 即可。
启用主题
编辑站点根目录的 _config.yml,把 theme 指向主题文件夹名:
1 | theme: xfm |
主题目录名必须是 xfm(或与 theme: 的值完全一致)。若你放到了 themes/xfm-theme,则 theme: xfm-theme。
安装依赖
Hexo 8 起核心不再内置渲染器与部分生成器,请在站点根目录安装:
1 | npm i hexo-renderer-marked hexo-renderer-ejs \ |
hexo init 生成的站点通常已自带上述依赖,可先运行 npm ls 确认。
按需增强
| 功能 | 依赖 | 说明 |
|---|---|---|
| RSS 订阅 | npm i hexo-generator-feed |
不装则导航栏 RSS 图标指向的 /atom.xml 为空 |
| KaTeX / MathJax | 无需安装 | 主题按 vendors.math 从 CDN 加载 |
| Mermaid | 无需安装 | 主题按 vendors.mermaid 从 CDN 加载 |
| 搜索 | 无需安装 | 主题内置 search.json 生成器 |
站点根目录的 package.json 需要包含 "hexo": { "version": "..." } 字段,Hexo 才会加载外部插件。这也是主题内置的 404 / sitemap / 搜索索引等生成器能否工作的前提。
切换模式
在主题 _config.yml 顶部切换全局形态:
1 | mode: docs # blog / notes / docs |
单篇文章可以覆盖它,实现同站混排:
1 |
|
需要的独立页面
部分页面类型需要在 source/ 下新建对应 Markdown,并在 front-matter 声明 type:
1 | hexo new page tags # front-matter 加 type: tags |
以标签页为例,生成的 source/tags/index.md 应为:
1 |
|
本地预览
1 | hexo clean |
打开 http://localhost:4000。若样式未生效,先确认 hexo clean 已执行——主题升级后旧的渲染缓存会干扰。
部署
主题本身不限制托管方式,静态产物在 public/,交给任意静态托管即可。
1 | npm i hexo-deployer-git |
站点 _config.yml:
1 | deploy: |
1 | hexo clean && hexo g && hexo d |
1 | hexo clean && hexo g |
Nginx 只需把 root 指向该目录。注意主题使用 pretty URL(目录 + index.html),确保 index.html 为默认索引文件。
_config.yml 的 url 必须填成站点最终访问地址。canonical、OG 图、sitemap.xml 都依赖它,填错会导致搜索引擎收录异常。
评论