准备
- 需要两个 github 仓库:
- 一个用于发布页面: shenbo.github.io
 
- 一个用于放源码: hexo-source
 
 
- 已配置好 hexo 的 VPS 服务器
 
1. 创建 hexo-source 仓库
- 在hexo的source目录下( ~/hexo/source)运行:
 
1 2 3 4 5 6 7 8
   | cd hexo/source
  git init git add . git commit -m "first commit" git remote add origin https://github.com/shenbo/hexo-source.git
  git push -u origin master
   | 
 
2. 搭建Webhook 服务
2.1 编写 hexo 部署命令
新建文件 hexo-d.sh ,内容如下:
1 2 3 4 5 6 7
   | cd ~/hexo/source git pull origin master
  cd ~/hexo hexo clean hexo generate hexo deploy
   | 
 
2.2 方案1:用 Python 接收 webhook
1 2 3 4 5 6 7 8 9 10 11 12 13
   | from wsgiref.simple_server import make_server import os
  def application(environ, start_response):     start_response('200 OK', [('Content-Type', 'text/html')])     print('blog.sh....')     os.system('/bin/bash hexo-d.sh &')         return [b'Hello, webhook!']
  httpd = make_server('', 9000, application) print('Serving HTTP on port 9000...')
  httpd.serve_forever()
   | 
 
1
   | nohup python3 webhook.py &
   | 
 
2.3 方案二:直接安装 webhook 应用
1
   | sudo apt-get install webhook
   | 
 
- 新建配置文件 hexo-hooks.json,内容为:
 
1 2 3 4 5 6 7
   | [   {     "id": "blog",     "execute-command": "hexo-d.sh",     "response-message": "job done!"   } ]
   | 
 
1
   | nohup webhook -hooks hexo-hook.json -verbose &
   | 
 
3. 配置 github 仓库的 webhook
进入 github.com -> repository -> hexo-source -> settings -> webhook
填写 webhook配置信息.
— ok!
4. 测试
在笔记本上 git clone hexo-source 仓库,然后 push 一下。