需求

搭建github个人博客

环境

安装node环境

参考版本
|环境|版本|
|-|-|
|node|v10.15.1|
|npm|6.9.0|

移步官方详细说明:hexo官网

步骤

全局安装hexo

1
$ npm install -g hexo-cli

建站

1
2
3
4
5
6
7
# hexo-test为文件夹名
$ hexo init hexo-test
$ cd hexo-test
# 安装依赖
$ npm install
# 启动本地服务
$ hexo server

更换主题

挑选主题
这里选择主题’autumn’

1
2
# 下载主题资源到 themes 文件夹下
$ git clone https://github.com/FrontendSophie/hexo-theme-autumn.git

主题资源放入themes文件夹:
themes下加入主题

修改 _config.yml 配置:

1
theme: hexo-theme-autumn

启动本地服务

1
$ hexo server

主题替换成功:
图片描述

修改其他配置

参见配置 | Hexo

部署到github

首先,在github新建一个名为<github用户名>.github.io的仓库
图片描述

然后,安装hexo-deployer-git

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

在 _congif.yml 中配置 deploy 字段

1
2
3
4
deploy:
type: git
repo: <你的仓库地址> # https://github.com/zimuZhao/zimuZhao.github.io
branch: master

执行自动部署命令

1
2
$ hexo clean
$ hexo deploy

Deploy成功后访问:https://zimuzhao.github.io/

文章撰写示例

在目录source->_posts下新建md文档

文档部分示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
---
title: hexo搭建github个人博客
author: ZIMU
tags:
- hexo
categories:
- demo
---

# 需求
搭建github个人博客

# 环境
安装[node环境][1]

...