搭建hexo博客,快速简洁高效,零成本搭建个人博客:hexo
搭建hexo博客,快速简洁高效,零成本搭建个人博客:hexo
Tansuan classmate1. 环境准备
在搭建 Hexo 之前,需要确保你的电脑有以下环境:
1.1 安装 Node.js
Hexo 依赖 Node.js 运行环境,推荐安装 LTS 版本。
- 下载地址:Node.js 官方网站
安装完成后,打开终端检查版本:
1 | node -v |
如果显示版本号,说明安装成功。
1.2 安装 Git
Hexo 部署和版本管理需要 Git 支持。
- 下载地址:Git 官方网站
安装完成后检查版本:
1 | git --version |
1.3 安装 Hexo CLI
通过 npm 安装 Hexo 命令行工具:
1 | npm install -g hexo-cli |
检查 Hexo 是否安装成功:
1 | hexo -v |
2. 初始化博客
在你想存放博客的目录执行以下命令:
1 | hexo init my-blog |
hexo init my-blog:创建一个名为my-blog的博客目录npm install:安装依赖包
3. 运行本地服务器
启动 Hexo 本地预览:
1 | hexo server |
浏览器打开 http://localhost:4000 即可查看博客首页。
4. 创建文章
Hexo 文章使用 Markdown 撰写:
1 | hexo new post "我的第一篇博客" |
文章会生成在 source/_posts 目录下,编辑完成后,可在本地预览:
1 | hexo clean |
hexo clean:清理缓存hexo g:生成静态文件hexo s:启动本地服务器
5. 选择主题
Hexo 支持丰富的主题,安装主题可以让博客更美观。
5.1 下载主题
常用主题推荐:
- Next 主题: https://github.com/theme-next/hexo-theme-next
- Yilia 主题: https://github.com/litten/hexo-theme-yilia
- Butterfly 主题: https://github.com/jerryc127/hexo-theme-butterfly
下载后,将主题放入 themes 文件夹,并在 _config.yml 中修改:
1 | theme: next |
重新生成博客:
1 | hexo clean |
6. 安装插件(可选)
常用 Hexo 插件:
- hexo-deployer-git(用于部署到 GitHub Pages):
1 | npm install hexo-deployer-git --save |
- hexo-generator-search(文章搜索插件):
1 | npm install hexo-generator-search --save |
- hexo-tag-plugins(增强 Markdown 标签支持):
1 | npm install hexo-tag-plugins --save |
7. 部署到 GitHub Pages
7.1 创建 GitHub 仓库
- 登录 GitHub(https://github.com)
- 创建仓库,名称为
username.github.io
7.2 配置 Hexo
编辑 _config.yml:
1 | deploy: |
7.3 部署命令
1 | hexo clean |
完成后,你的博客就可以通过 https://username.github.io 访问。
8. Hexo 常用命令汇总
| 命令 | 功能 |
|---|---|
| hexo init [folder] | 初始化博客 |
| hexo new post “title” | 新建文章 |
| hexo clean | 清理缓存 |
| hexo g | 生成静态文件 |
| hexo s | 本地预览 |
| hexo d | 部署博客 |
9. 参考资源
- Hexo 官方网站: https://hexo.io/
- Hexo 中文文档: https://hexo.io/zh-cn/docs/
- Hexo GitHub 仓库: https://github.com/hexojs/hexo
- 再记住一个推送的命令哦:
hexo cl; hexo g; hexo d
恭喜你!你已经成功搭建了属于自己的 Hexo 博客,可以开始写文章、分享知识、展示作品了。
