1. 創建倉庫
在github上創建名稱為username.github.io倉庫
2. Clone
將倉庫clone到本地
$ git clone https://github.com/username/username.github.io
3. Hello World
創建index.html
$ cd username.github.io
$ echo "Hello World" > index.html
4. push
提交代碼并push
$ git add --all
$ git commit -m "Initial commit"
$ git push -u origin master
5. 驗證
訪問username.github.io,這樣就能看到Hello World了
6. 域名映射
將域名映射到username.github.io
$ echo "www.yourdomain.com" > CNAME
$ git commit -m "Create CNAME"
$ git push origin master
在域名管理添加一條CNAME記錄,將www.yourdomain.com指向username.github.io
7. 安裝Hexo
7.1 什么是Hexo
Hexo is a fast, simple and powerful blog framework. You write posts in Markdown (or other languages) and Hexo generates static files with a beautiful theme in seconds.
7.2 安裝Git
7.3 安裝Node.js
$ wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh
$ nvm install 4
7.4 安裝Hexo
$ npm install -g hexo-cli
$ hexo init <folder>
$ cd <folder>
$ npm install
$ hexo server
這樣就可以通過localhost:4000訪問了
7.5 部署到github
安裝hexo-deployer-git
$ npm install hexo-deployer-git --save
修改_config.yml
deploy:
type: git
repo: <repository url>
部署到github
$ hexo deploy
但是部署后會覆蓋掉github上的CNAME和README.md,需要在hexo的source目錄添加CNAME和README.md,但是執行hexo generate后README.md會生成README.html,因此需要配置下,不讓其渲染README.md。
修改Hexo目錄下的_config.yml
skip_render: README.md
然后運行
$ hexo g
$ hexo d
這樣就部署到github上了,并且不會覆蓋掉已寫好的CNAME和README.md了。
7.6 寫blog
$ hexo new "Markdown"
會在source/_posts/
目錄下生成Markdown.md
文件,編輯該文件后
$ hexo g
$ hexo d