使用Hexo在Gitee上搭建个人博客

使用 Hexo 搭建个人博客

官网:https://hexo.io/zh-cn/docs/

安装

1
npm install -g hexo-cli

如果使用 npm 下载失败,推荐使用 yarn

1
yarn global add hexo-cli

使用 hexo-cli 一键配置


1
npm install hexo

熟悉 npm 可以使用 hexo 自定义配置

搭建

1
2
hexo init <folder>
cd <folder>

使用 npm 下载

1
npm install

使用 yarn 下载

1
yarn

目录

1
2
3
4
5
6
7
8
.
├── _config.yml
├── package.json
├── scaffolds
├── source
| ├── _drafts
| └── _posts
└── themes

_config.yml

网站的配置信息

scaffolds

模版 文件夹。当您新建文章时,Hexo 会根据 scaffold 来建立文件。

Hexo的模板是指在新建的文章文件中默认填充的内容。例如,如果您修改 scaffold/post.md 中的Front-matter内容,那么每次新建一篇文章时都会包含这个修改。

source

资源文件夹是存放用户资源的地方。除 _posts 文件夹之外,开头命名为 _ (下划线)的文件 / 文件夹和隐藏的文件将会被忽略。Markdown 和 HTML 文件会被解析并放到 public 文件夹,而其他文件会被拷贝过去。

themes

主题

本地运行测试

1
2
hexo generate
hexo server

打开hexo的服务,在浏览器输入localhost:4000就可以看到你生成的博客了

Gitee 搭建服务

创建库

创建库

==库名最好与用户名相同,网址可以缩写==

开启服务

开启服务

部署

修改配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Site
# 网站标题
title: View Room
# 网站副标题
subtitle: 望间
# 描述(SEO)
summary: 一个前端学习者的个人博客
# 关键字(SEO)
keywords: 前端
# 作者
author: Ruins
# 语言
language: zh-CN
timezone: ''

# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
# 网站路径(非自定义,gitee 生成的)
url: https://dreamruins.gitee.io
# 网站根路径
# root: ''
# 文章路径
permalink: :year/:month/:day/:title/
permalink_defaults:
pretty_urls:
trailing_index: true # Set to false to remove trailing 'index.html' from permalinks
trailing_html: true # Set to false to remove trailing '.html' from permalinks

# Deployment
deploy:
type: git
# 库路径
repo: https://gitee.com/dreamruins/dreamruins
# 分支
branch: master
# 提交文本
message: 部署

我为重要的配置给出了的注释,你可以根据自己的需求进行个性化配置

如果你的博客部署在二级路径上,则需要配置 root 根路径,就可以取消上面的 root 配置项的注释进行配置

1
2
url: http://xxx.gitee.io/blog
root: /blog/

安装 hexo-deployer-git

1
2
# git 部署工具
npm install hexo-deployer-git --save

部署

1
2
3
4
5
6
7
8
# 清除缓存
hexo clean

# 生成静态资源
hexo generate

# 部署
hexo deploy