Windows下安装Hexo以及发布到Github Pages

简介

Hexo是一个快速,简单而强大的博客框架。

安装

Hexo官网

1
npm install hexo-cli -g

初始化

1
2
3
hexo init <folder>
cd <folder>
npm install

这个命令会初始化博客的目录,执行命令后生成以下文件

1
2
3
4
5
6
7
8
├── .deploy #部署到GitHub上的内容目录
├── public #静态网页内容输出目录
├── scaffolds #layout模板文件目录
├── source #文章源码目录,404文件、favicon.ico文件,CNAME文件等
| ├── _posts #发布文章
├── themes #主题文件目录
├── _config.yml #全局配置文件
└── package.json #应用程序数据

发布并打开hexo服务

1
2
$ hexo g #生成
$ hexo s #启动本地服务,进行文章预览调试

http://localhost:4000

目前使用的hexo版本为

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
hexo: 3.6.0
hexo-cli: 1.1.0
os: Windows_NT 10.0.17134 win32 x64
http_parser: 2.7.0
node: 9.8.0
v8: 6.2.414.46-node.21
uv: 1.19.2
zlib: 1.2.11
ares: 1.13.0
modules: 59
nghttp2: 1.29.0
napi: 2
openssl: 1.0.2n
icu: 60.2
unicode: 10.0
cldr: 32.0.1
tz: 2017c

使用背景图片

1.站点配置

1
post_asset_folder:true

2.根目录下执行

1
npm install hexo-asset-image --save

3.命令新建文章

1
hexo new "test"

4.在/_posts下生成与test.md名称一样的文件夹test,代码引用图片

1
![描述](test/background.png)

使用tags

1.新建一个页面,命名为tags。命令如下:

1
hexo new page "tags"

2.编辑tags文件夹下的index.md

1
2
3
4
5
6
7
8

---
title: tags
date: 2018-05-16 15:55:45
type: "tags"
layout: "tags"
comments: false
---

3.在菜单中添加链接。编辑主题的 themes/next/_config.yml ,添加tags到menu中

1
2
3
4
5
menu:
home: /
archives: /archives/
categories: /categories/
tags: /tags/

使用categories

1.新建一个页面,命名为categories。命令如下:

1
hexo new page "categories"

2.编辑categories文件夹下的index.md

1
2
3
4
5
6
7
8

---
title: categories
date: 2018-05-16 15:55:54
type: "categories"
layout: "categories"
comments: false
---

3.在菜单中添加链接。编辑主题的 themes/next/_config.yml ,添加categories到menu中

1
2
3
4
5
menu:
home: /
archives: /archives/
categories: /categories/
tags: /tags/

使用about

1.新建一个页面,命名为about。命令如下:

1
hexo new page "about"

2.编辑about文件夹下的index.md

1
2
3
4
5

---
title: 关于我
date: 2017-06-26 00:00:01
---

3.在菜单中添加链接。编辑主题的 themes/next/_config.yml ,添加about到menu中

1
2
3
4
5
6
menu:
home: /
archives: /archives/
categories: /categories/
tags: /tags/
about: /about/

使用next主题

1.在站点根目录下运行以下命令

1
$ git clone https://github.com/iissnan/hexo-theme-next themes/next

2.设置站点配置

1
theme: next

安装hexo-git

1.安装

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

2.添加部署代码

1
2
3
4
5
# Deployment
deploy:
type: git
repository: git@github.com:username/username.github.io.git
branch: master

3.在github建立仓库,名称为username.github.io,配置好后执行命令可发布到Github Pages中

1
$ hexo clean & hexo g & hexo d

相关主题