Hexo+Github搭建个人博客

前言

Hexo是一个简单地、轻量地、基于Node.js的一个静态博客框架, 部署方便快速。
而将博客部署在github上可以省去服务器的成本以及系统运维的精力。


安装前需准备

服务器系统环境:Mac OS
Node.js : 前往官网 https://nodejs.org/en/download/ 下载与系统对应的安装包;
GitHub账户 : 注册github账户, 并建立一个名称为 xizhiming.github.io 的 repository(xizhiming是我github的username)。


Hexo 安装与配置

安装

1
2
3
4
# 全局安装
$ sudo npm install -g --no-optional hexo
# 选择指定文件夹, 创建项目文件
$ hexo init Brook.xi_hexo

配置

站点配置文件../_config.yml

站点描述

1
2
3
4
5
6
7
title: Brook.Xi
subtitle: 一个数据分析师的学习心得与工作总结
description: 毋意, 毋必, 毋固, 毋我
author: Brook.Xi
language: zh-Hans
timezone:
avatar: images/me.jpeg

主题设置

1
theme: next

开发模式设置

1
2
3
4
deploy:
type: git
repo: https://github.com/{github_username}/{github_username}.github.io
branch: master

Next 安装与配置

安装

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

配置

主题配置文件../themes/next/_config.yml

选择scheme

1
2
3
# scheme: Muse  #默认 Scheme, 这是 NexT 最初的版本, 黑白主调, 大量留白
# scheme: Mist #Muse 的紧凑版本, 整洁有序的单栏外观
scheme: Pisces #双栏 Scheme, 小家碧玉似的清新

设置社交账号

1
2
social:
GitHub: https://github.com/xizhiming

添加「标签」页面

1
2
3
4
5
6
7
$ hexo new page tags
# 修改页面内容(../source/tags/index.md)
---
title: 标签
date: 2016-08-29 11:54:24
type: "tags"
---

添加「分类」页面

1
2
3
4
5
6
7
$ hexo new page categories
# 修改页面内容(../source/categories/index.md)
---
title: 分类
date: 2016-08-29 11:58:40
type: "categories"
---

设置菜单

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

本地测试

1
2
3
$ cd Brook.xi_hexo/
$ npm install hexo-server --save
$ hexo server

访问 http://localhost:4000/ 页面查看


上传至Github

安装插件

1
2
$ cd Brook.xi_hexo/
$ npm install hexo-deployer-git --save

上传

1
2
$ hexo clean
$ hexo deploy

That’s all.
Happy writing!