Hexo踩坑之路

Step one

  • 注册一个github账号,创建一个[yourname].github.io的repository。

  • 本地生成SSH公钥(关于SSH协议,下篇博客讲解)

1
$ ssh-keygen -t rsa -C "your_email@youremail.com"
1
$ cd ~/.ssh
1
2
3
$ ls
authorized_keys2 id_rsa known_hosts
config id_rsa.pub
1
$ vim id_rsa.pub
  • 复制公钥到Github

Step two

  • 安装node
1
$ brew install node
  • 安装hexo
1
$ npm install hexo-cli -g
  • 初始化hexo
1
$ hexo init blog(文件夹名字随意)
  • 安装deployer扩展
1
$ npm install hexo-deployer-git --save

Step three

  • 修改hexo配置文件_config.xml,指向github中仓库
1
2
3
4
deploy:
type: git
repo: git@github.com:yourname/yourname.github.io.git
branch: master
  • 新建一篇文章,保存在source/_post下面
1
$ hexo new test
  • 修改test.md
1
2
3
4
5
6
7
---
title: Hexo踩坑之路
date: 2017-09-24 17:21:51
tags:

---
Hello World!
  • 生成静态文件,会在当前目录下生成一个新的叫做public的文件夹
1
$ hexo generate
  • 启动本地web服务,用于博客的预览
1
$ hexo server
  • 部署博客到远端
1
$ hexo deploy

More

  • 下载主题(以next为例)
1
$ cd blog
1
$ git clone https://github.com/iissnan/hexo-theme-next themes/next
  • 修改配置文件_config.yml
1
theme: next