使用hexo生成和部署网站

1. 下载和安装nodejs

https://nodejs.org/en/

2. 下载和安装hexo

https://hexo.io/

3. 建立一个文件夹,用来保存hexo项目文件

例如 C:\someone\hexo blog someone

4. 初始化hexo项目

在 git bash里面输入

1
2
$ hexo init
$ npm install

项目即在hexo blog someone文件夹下建立了。

5. 编辑网站基本信息

在 C:\someone\hexo blog someone文件夹下,编辑 _config.yml 文件

其中:

1
2
3
4
5
6
7
8
9
10
11
12
# Site
title: someone's blog
author: someone
# URL
url: https://someone.github.io

# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: git
repository: https://github.com/someone/someone.github.io
branch: master

6. 拷贝markdown文档到_post文件夹

将准备好的markdown文件,拷贝到 \hexo blog someone\source\_posts 中。
最好按照如下方式命名:

2010-01-04-ubuntur8s.md

另外, 在每个markdown文件的头部增加YAML说明。

1
2
3
4
5
6
---
layout: post
title: "群落系统发育研究不能脱离理论框架"
date: 2020-12-30 09:14:00+08:00
tags: [随笔]
---

7. 生成网站

在git bash中输入:

1
$ hexo generate

8. 预览网站

在git bash中输入:

1
$ hexo serve

然后, 在浏览器地址栏输入localhost:4000/即可预览网站

9. 增加关于本人的about页面:

分成两步

(1) 在网站下,保证 someone.github.io/about 网址有相应网页

1
$ hexo new page about

此命令运行之后,hexo blog someone\source 下即生成about文件夹。编辑其中的 index.md 内容即可。

(2)让网站首页显示about的链接

在需要更改hexo blog someone\node_modules\hexo-theme-landscape下的_config.yml文件,
menu: 下增加 About: /about 一行。

1
2
3
4
5
6
7
# Header
menu:
Home: /
Archives: /archives
About: /about
rss: /atom.xml
banner: "images/banner.jpg"

如要显示不同的banner, 则将banner.jpg的照片做相应置换即可。

10. 部署到github

安装hexo-deployer-git,在git bash中输入命令:

1
$ npm install hexo-deployer-git --save

在git bash中输入:

1
$ hexo deploy