Hexo 博客使用说明书
📖 目录
快速开始
1. 环境要求
- Node.js 18+
- Git
- SSH 密钥(已配置免密登录服务器)
2. 项目结构
demo-site/
├── source/ # 文章源码
├── public/ # 生成的静态文件
├── _config.yml # Hexo 配置文件
├── deploy/ # 部署脚本
│ ├── github-sync.sh # GitHub 同步脚本
│ └── deploy.sh # 直接部署脚本
└── .github/
└── workflows/
└── deploy.yml # GitHub Actions 自动部署配置
日常写作流程
1. 创建新文章
# 进入项目目录
cd demo-site
# 创建新文章
npx hexo new post "文章标题"
# 文章将创建在: source/_posts/文章标题.md
2. 编辑文章
# 使用你喜欢的编辑器编辑
vim source/_posts/文章标题.md
# 或者使用 VS Code
code source/_posts/文章标题.md
文章格式(Front-matter):
---
title: 文章标题
date: 2024-01-01 12:00:00
tags:
- 标签1
- 标签2
categories:
- 分类
---
文章内容...
3. 本地预览
# 启动本地服务器
npx hexo server
# 访问 http://localhost:4000
4. 生成静态文件
npx hexo clean # 清理缓存
npx hexo generate # 生成静态文件
部署方式
我们提供两种部署方式:
- GitHub 自动部署(推荐) - 推送到 GitHub 自动部署到服务器
- 本地直接部署 - 直接通过脚本部署到服务器
GitHub 自动部署(推荐)
工作流程
本地编辑 → 推送到 GitHub → GitHub Actions 自动构建 → 自动部署到服务器
配置步骤(已完成)
- ✅ GitHub 仓库: https://github.com/luduihang/MyBlog
- ✅ GitHub Actions 工作流已配置 (
.github/workflows/deploy.yml) - ✅ 服务器 Nginx 已配置
日常使用
# 进入项目目录
cd demo-site
# 1. 创建并编辑文章
npx hexo new post "文章标题"
vim source/_posts/文章标题.md
# 2. 推送到 GitHub(自动触发部署)
./deploy/github-sync.sh
或者手动操作:
git add .
git commit -m "更新博客"
git push origin main
查看部署状态
访问 https://github.com/luduihang/MyBlog/actions 查看自动部署进度。
本地直接部署
如果不想通过 GitHub,可以直接部署到服务器:
# 1. 生成静态文件
cd demo-site
npx hexo clean
npx hexo generate
# 2. 直接部署到服务器
./deploy/deploy.sh
# 或者使用 rsync
rsync -avz --delete public/ tecent-server:/home/ubuntu/code/project/
常见问题
Q1: 部署后网站显示 404?
A: 检查 Nginx 配置和文件权限:
ssh tecent-server "sudo systemctl status nginx && ls -la /home/ubuntu/code/project/"
Q2: 如何更新网站内容?
A:
- 编辑文章:
vim source/_posts/文章.md - 推送到 GitHub:
./deploy/github-sync.sh - 自动部署完成
Q3: 如何备份网站?
A:
# 在服务器上备份
ssh tecent-server "tar -czvf /backup/blog-$(date +%Y%m%d).tar.gz /home/ubuntu/code/project/"
Q4: 如何启用 HTTPS?
A: 使用 Certbot 申请免费 SSL 证书:
ssh tecent-server
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d litearch.cn -d www.litearch.cn
🎉 恭喜!
你的 Hexo 博客已经成功部署!现在你可以:
- 📝 写作:
npx hexo new post "标题" - 🚀 部署:
./deploy/github-sync.sh - 🌐 访问:https://litearch.cn
有任何问题随时问我!🚀
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 kipleyarch@gmail.com