Hexo 博客搭建与配置指南
📖 简介
Hexo 是一个快速、简洁且高效的静态博客框架。它使用 Markdown解析文章,在几秒内即可生成静态网页。本指南将帮助您快速搭建并配置一个 Hexo 博客。
🚀 快速开始
环境准备
安装 Node.js
安装 Git
安装 Hexo
打开终端(命令提示符)并执行:
初始化博客
1 2 3
| hexo init my-blog cd my-blog npm install
|
本地预览
1 2 3 4 5 6 7
| hexo clean
hexo g
hexo s
hexo d
|
⚙️ 基本配置
配置文件
博客的主要配置文件为 _config.yml,位于博客根目录下。
常用配置项
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| title: 我的博客 subtitle: '' description: '' keywords: author: 作者名 language: zh-CN timezone: ''
url: http://yoursite.com root: / permalink: :year/:month/:day/:title/
source_dir: source public_dir: public
new_post_name: :title.md default_layout: post
|
🎨 主题安装与配置
安装主题
以我所使用的stellar 主题为例:
1 2
| cd my-blog git clone https://github.com/stellar-theme/hexo-theme-syellar themes/stellar
|
启用主题
修改 _config.yml:
主题配置
主题有自己的配置文件 themes/stellar/_config.yml,可进行个性化设置。
📝 写作与发布
创建新文章
文章文件位于 source/_posts/文章标题.md
文章 Front-matter
1 2 3 4 5 6
| --- title: 文章标题 date: 2024-05-20 10:00:00 tags: [标签1, 标签2] categories: 分类名 ---
|
常用命令
hexo new [layout] <title> - 新建文章
hexo clean - 清除缓存
hexo generate 或 hexo g - 生成静态文件
hexo server 或 hexo s - 启动本地服务器
hexo deploy 或 hexo d - 部署到远程仓库
🌐 部署到 GitHub Pages
准备工作
- 创建 GitHub 仓库,命名为
用户名.github.io
- 安装部署插件:
1
| npm install hexo-deployer-git --save
|
配置部署
修改 _config.yml:
1 2 3 4
| deploy: type: git repo: https://github.com/用户名/用户名.github.io.git branch: main
|
部署命令
1 2 3
| hexo clean hexo generate hexo deploy
|
🔧 常用插件
1 2 3 4 5 6 7 8 9 10 11
| npm install hexo-generator-feed --save
npm install hexo-generator-sitemap --save
npm install hexo-generator-searchdb --save
npm install hexo-wordcount --save
|
💡 实用技巧
自定义页面
草稿功能
1 2
| hexo new draft "草稿标题" hexo publish "草稿标题"
|
图片引用
- 将图片放入
source/images/ 目录
- 在文章中引用:
1
| 
|
🛠️ 故障排除
常见问题
部署失败
- 检查 Git 配置
- 确认仓库地址正确
- 检查网络连接
页面无法加载
主题不生效
- 确认主题文件夹名称正确
- 检查
_config.yml 中 theme 配置
📚 学习资源
提示:配置时建议备份原配置文件,每次只修改少量配置并测试效果。