Hexo 博客搭建教程
基于 J3455(Ubuntu 22.04)部署,使用 NexT 主题,部署到 GitHub Pages
1. 环境准备
1.1 Node.js
J3455 已安装 Node.js v20.20.2 + npm 10.8.2,通过 nvm 管理。
如果需在其他机器上安装:
1 2 3
| curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash source ~/.zshrc nvm install 20
|
1.2 Git + GitHub SSH
1 2 3 4 5 6 7 8
| ssh -T git@github.com
ssh-keygen -t ed25519 -C "your_email@qq.com" cat ~/.ssh/id_ed25519.pub
|
1.3 代理(可选,国内环境建议)
1
| export ALL_PROXY=socks5://127.0.0.1:10808
|
2. 安装 Hexo
1 2 3
| npm install -g hexo-cli hexo --version
|
3. 初始化项目
1 2 3 4
| cd ~ hexo init hexo-blog cd hexo-blog npm install
|
生成的项目结构:
1 2 3 4 5 6 7 8
| hexo-blog/ ├── _config.yml # 博客主配置文件 ├── package.json # 依赖管理 ├── scaffolds/ # 文章模板 ├── source/ │ └── _posts/ # Markdown 文章目录 ├── themes/ # 主题目录 └── public/ # 生成的静态文件
|
4. 安装主题(NexT)
1 2
| cd ~/hexo-blog git clone https://github.com/next-theme/hexo-theme-next themes/next
|
5. 基本配置
编辑 _config.yml,修改关键字段:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| title: 多肉的博客 subtitle: 微磁模拟 & 技术笔记 description: OOMMF、skyrmion、Linux、编程 author: 多肉 language: zh-CN timezone: Asia/Shanghai
url: https://imu-wys.github.io
theme: next
deploy: type: git repo: git@github.com:imu-wys/imu-wys.github.io.git branch: master
|
创建主题配置文件 _config.next.yml:
1 2 3 4 5 6 7 8 9 10 11
| scheme: Gemini menu: home: / || fa fa-home archives: /archives/ || fa fa-archive tags: /tags/ || fa fa-tags categories: /categories/ || fa fa-th sidebar: position: left display: post footer: since: 2021
|
6. 写文章
新建
在 source/_posts/ 下生成 Markdown 文件:
1 2 3 4 5 6 7 8 9
| --- title: 文章标题 date: 2026-05-20 20:00:00 tags: - 标签1 - 标签2 ---
这里是正文,支持完整 Markdown 语法。
|
Front-matter 字段
| 字段 |
必填 |
说明 |
title |
✅ |
文章标题 |
date |
✅ |
发布日期 |
tags |
❌ |
标签列表 |
categories |
❌ |
分类 |
cover |
❌ |
封面图路径 |
7. 本地预览
1 2 3
| hexo clean hexo g hexo s -p 4000
|
8. 部署到 GitHub Pages
1 2 3 4 5
| npm install hexo-deployer-git --save
hexo clean && hexo g && hexo d
|
访问 https://imu-wys.github.io 查看效果。
9. 常用命令速查
| 命令 |
作用 |
hexo new "标题" |
新建文章 |
hexo clean |
清理缓存 |
hexo g |
生成静态文件 |
hexo s |
本地预览 |
hexo d |
部署到 GitHub |
hexo clean && hexo g && hexo d |
三连发布 |
10. 在 code-server 中写作
博客路径:/home/wys/hexo-blog/
- 打开 https://49.232.196.148/code/
- File → Open Folder →
/home/wys/hexo-blog
- 编辑
source/_posts/ 下的 Markdown
- 终端运行
hexo g && hexo d 发布
11. 文章恢复说明
从 GitHub Pages 已发布的 HTML 逆向提取了原始博客的 14 篇文章,放在 source/_posts/ 目录下。内容为纯文本格式提取,公式和代码块需手动格式化。论文章节(第 2、3、4、5、6 章)内容较短,建议补充。
本教程由阿财自动生成,基于 J3455 实际部署过程。