Hexo+GitHub Pages搭建个人博客教程

  配置过程有点麻烦boring,自己跟着教程做还是遇到了几个坑,毕竟网上的教程都有几个年头了。在此详细地记录了基础配置的每一步,只想抬一手想搭博客的[程序猿们]

软件安装

Git

  • 点击下载安装包,选择你的操作系统类型,然后,稍等片刻即可
  • 打开安装包,一直Next下去

Node.js

配置Github

建立Repository

当然,你要先有一个Github账号,然后建立与你用户名相对应的Repository,比如我的用户名是JuneOne,那么仓库名就为JuneOne.github.io

安装Hexo

Installation

随便在哪,右键->Git Bash Here,输入命令:

1
npm install -g hexo

在安装时会遇到如下Warning:

npm WARN deprecated swig@1.4.2: This package is no longer maintained

其实已经在安装Hexo了,稍等一会儿。

Quick Start

选一个路径建立文件夹「Hexo」(比如D:\Hexo),然后在该文件夹中右键->Git Bash Here,输入下面的命令:

1
hexo init

INFO Start blogging with Hexo!

提示hexo安装成功,执行下面的命令,使hexo在本地开启,便可在http://localhost:4000查看博客效果

1
hexo s

INFO Start processing
INFO Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.

部署到Github,修改「Hexo」目录下的_config.yml

1
2
3
4
# Deployment
## Docs: http://hexo.io/docs/deployment.html
deploy:
type:

修改为:

1
2
3
4
5
6
# Deployment
## Docs: http://hexo.io/docs/deployment.html
deploy:
type: git
repository: git@github.com:JuneOne/JuneOne.github.io.git
branch: master

“:”号后面有空格,URL必须是SSH形式的(点击查看如何生成SSH密钥),当然JuneOne换成你的用户名。输入以下命令在Github上部署你的博客:

1
hexo d -g

遇到的问题

Question 1

ERROR Deployer not found: git

Solution:

1
npm install hexo-deployer-git --save

Question 2

*** Please tell me who you are.
Run
git config --global user.email “you@example.com”
git config --global user.name “Your Name”

Solution:

1
2
git config --global user.email "你的邮箱"
git config --global user.name "用户名"

在弹出的界面中输入登录密码,再次输入hexo d部署。稍等片刻,打开https://用户名.github.io

配置Hexo主题

这里具体介绍一下NexT主题的配置,当然你可以去官网选择喜欢的主题。

在「Hexo」目录下右键->Git Bash Here,然后执行以下命令,将主题下载到themes/next

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

修改安「Hexo」目录下的config.yml中的theme属性,将其设置为next

1
2
3
4
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: next

更新NexT主题

1
hexo d -g

基本操作

新文章

1
hexo new "文章题目"

在\hexo\source\_posts\下找到对应的.md文件,编辑文章内容

在本地查看

1
hexo s

打开localhost:4000即可查看博客的效果

部署到Github

1
hexo d -g

g是generate,生成静态页面;d是deploy,部署到github

Fork me on GitHub