使用 Hexo 搭建静态博客并部署到 GitHub Pages
使用 Hexo 搭建静态博客并部署到 GitHub Pages
这是我搭建的博客
一、环境准备
1.安装 Node.js
Hexo 基于 Node.js,需先安装:
# Ubuntu/Debian
sudo apt update
sudo apt install nodejs npm
# macOS(通过 Homebrew)
brew install node
# 验证安装
node -v
npm -v
# 安装国内淘宝镜像
npm install -g cnpm
# 验证安装
cnpm -v
windows直接安装nodejs msi
2.安装Git
# Ubuntu/Debian
sudo apt install git
git --version
windows直接安装git for windows
3.安装 Hexo
cnpm install -g hexo-cli
hexo -v # 验证安装
二、初始化 Hexo 博客
1.创建项目目录
hexo init blog
cd blog
2.安装依赖
cnpm install
3.安装主题
git clone https://github.com/EvanNotFound/hexo-theme-redefine.git themes/redefine
修改博客目录下的 _config.yml 文件,使用redefine主题:
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: redefine
4.本地预览
hexo server #或 hexo s
三、配置 GitHub Pages
1.创建 GitHub 仓库
仓库名必须为 username.github.io(如 Juenfy.github.io)。
选择 Public 可见性,初始化时可跳过 .gitignore 和 README。
2.配置 Hexo 部署设置
修改博客目录下的 _config.yml 文件:
# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: git
repo: https://github.com/Juenfy/Juenfy.github.io.git
branch: master
3.安装部署插件
cnpm install hexo-deployer-git --save
四、撰写与发布文章
1.新建文章
hexo new "Hello World" # 在 source/_posts 下生成 Hello World.md Markdown文件
2.编辑文章
用 Markdown 语法编写内容(支持 Front-matter 配置):
---
title: Hello World
date: 2025-06-18 15:59:04
tags:
- 标签1
- 标签2
categories
- 分类1
- 分类2
---
这里是正文内容...
3.生成静态文件
hexo generate # 或 hexo g
4.部署到 GitHub
hexo deploy # 或 hexo d
部署完后通过username.github.io访问即可。
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: