博客搭建 - hexo + github + coding.net + next 主题

前言

   从大学接触计算机,也能算一个10年的码农了,之前有个blog,但是好久没有更新了,也可能是太忙,也可能是懒了,什么东西都往Evernote里一放就完事了,没有很好的整理,最近突然想搭建一个自己的blog,找遍全世界,终于找打自己喜爱的,没错,就是hexo,简约清新,写法符合自己的习惯,闲聊至此。
   重新写blog的目的,一个是为了更好的总结自己的学习足迹,锻炼自己的表达,更重要的还能认识大家,一起学习交流。欢迎拍砖~~~

hexo 安装

1
$ npm install -g hexo

博客目录创建

1
2
$ mkdir /Users/xgz/blog
$ chmod -R 777 /Users/xgz/blog

初始化

1
2
$ cd /Users/xgz/blog
$ hexo init

生成静态页面

1
$ hexo generate (or hexo g)

启动服务

1
$ hexo server

访问服务

浏览器输入http://localhost:4000

配置github

创建Repository,仓库名必须为 username/username.github.io , 例如 jingjiaguo/jingjiaguo.github.io

配置全局根目录_config.yml(不是主题下的_config.yml),下面是我的配置,hexo部署到多个repo,ssh key需要配置下,未配置的话,需要输入对应的用户名和密码(解决 Github Pages 禁止百度爬虫,还需配置dns,后续说明)

1
2
3
4
5
6
7
8
9
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
- type: git
repo: https://github.com/jingjiaguo/jingjiaguo.github.io.git
branch: master
- type: git
repo: https://git.coding.net/jingjiaguo/jingjiaguo.git
branch: coding-pages

安装 hexo-deployer-git

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

上传部署

1
$ hexo deploy

浏览器中输入http://jingjiaguo.github.io

没有配置自动部署的部署

1
2
3
$ hexo clean
$ hexo generate
$ hexo deploy

常用命令

1
2
3
4
5
6
7
hexo new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成静态页面至public目录
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)
hexo deploy #将.deploy目录部署到GitHub
hexo help #查看帮助
hexo version #查看Hexo的版本

next 主题安装

1
2
$ cd /Users/xgz/blog
$ git clone https://github.com/iissnan/hexo-theme-next themes/next

启用next主题,全局根目录_config.yml

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

scheme设定,next主题下_config.yml

1
2
3
#scheme: Muse
#scheme: Mist
scheme: Pisces

解决 Github Pages 禁止百度爬虫

注册账号

https://coding.net/user

创建项目

格式: [username]/[username]

全局_config.yml配置,hexo 部署到多个repo

1
2
3
4
5
6
7
8
9
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
- type: git
repo: https://github.com/jingjiaguo/jingjiaguo.github.io.git
branch: master
- type: git
repo: https://git.coding.net/jingjiaguo/jingjiaguo.git
branch: coding-pages

开启pages 服务 & 绑定域名

logo

访问

http://jingjiaguo.com/

百度站长工具

logo

参考:

https://hexo.io/docs/deployment.html
http://notes.iissnan.com/
http://theme-next.iissnan.com/getting-started.html
http://notes.iissnan.com/2015/something-about-next/
http://www.jianshu.com/p/2d0707964202
http://jerryzou.com/posts/feasibility-of-allowing-baiduSpider-for-Github-Pages/
https://www.zybuluo.com/mdeditor#545958
http://baixin.io/archive/