使用 Github Pages 和 Hexo 部署个人博客

Anrola Lv1

使用Github Pages 和 Hexo 部署个人blog。

前置

需要:
1.Github账号。
2.安装Git(配置好与GitHub连接)。
3.安装Node.js

创建Hexo

在空文件夹右键选择Open Git Bash here
输入npm install -g hexo-cli
此时Hexo已经安装到系统全局环境。

输入hexo init myblogs
此时会在myblogs文件夹下初始化Hexo

输入cd myblogs移动到myblogs文件夹。
输入npm install安装所需的依赖。

输入hexo s预览网页。
默认访问http://localhost:4000/

Github配置

在GitHub新建仓库,仓库名格式为“Github用户名.github.io”。

现在回到myblogs文件夹,在_config.yml里配置参数。

1
2
3
4
5
6
# Deployment 
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: git
repo: git@github.com:Anrola-star/Anrola-star.github.io.git
branch: main

type: git
repo: 仓库的SSH链接
branch: 分支名

输入npm install hexo-deployer-git --save安装git插件。

1
2
3
4
5
6
#清理缓存
hexo clear
#生成文件
hexo generate
#部署到github
hexo depoly

部署成功之后可以访问“https://用户名.github.io”进入博客。

主题安装

1
2
#安装redefine主题
npm install hexo-theme-redefine@latest

_config.yml里找到theme项,改为redefine。

1
2
3
4
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: redefine

Redefine 推荐使用独立的配置文件
1.在你的 Hexo 博客根目录下,新建一个名为 _config.redefine.yml 的文件。
2.打开 Redefine 主题的官方配置文件,将其中的所有内容复制到你新建的 _config.redefine.yml 文件中。

配置好后重新部署即可。
官方文档:
https://redefine-docs.ohevan.com/zh/docs
https://hexo.io/zh-cn/docs/

书写

1
$ hexo new "My New Post"

创建一个新文章,以md格式存储在/source/_posts/
也可以手动在此目录创建md文件,但是需要注意添加参数:

1
2
3
4
5
6
7
8
---
title: Hello World
date: 2013/7/13 20:46:25
comments: true #开启文章的评论功能
published: true #文章是否发布
tags: c++ #标签(不适用于分页)
categories: c++ #分类(不适用于分页)
---

如果该文章需要展示图片,pdf等其他文件时,需要自行创建一个同名文件夹。
示例,如果你的markdown文件叫做_posts/markdown-demo.md的话,同名文件夹就是_posts/markdown-demo/。

如果你将***.github.io/_config.yml中的post_asset_folder设置为true,那么使用hexo命令,则会自行创建这个同名文件夹。

  • Title: 使用 Github Pages 和 Hexo 部署个人博客
  • Author: Anrola
  • Created at : 2026-07-26 20:41:49
  • Updated at : 2026-07-27 00:01:36
  • Link: https://redefine.ohevan.com/2026/07/26/hello-world/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
使用 Github Pages 和 Hexo 部署个人博客