本地安裝hexo步驟
注意:本節教程只針對Windows用戶,Linux和Mac用戶請移步hexo安裝。
- 安裝Git
下載 msysgit 並執行即可完成安裝。
- 安裝Node.js
在 Windows 環境下安裝 Node.js 非常簡單,僅須下載安裝文件並執行即可完成安裝。
- 安裝hexo
利用 npm 命令即可安裝。(在任意位置點擊鼠標右鍵,選擇Git bash)
npm install -g hexo
安裝完成后,在你喜愛的文件夾下(如H:\hexo),執行以下指令(在H:\hexo內點擊鼠標右鍵,選擇Git bash),Hexo 即會自動在目標文件夾建立網站所需要的所有文件。創建hexo文件夾
hexo init
安裝依賴包
本地查看
現在我們已經搭建起本地的hexo博客了,執行以下命令(在H:\hexo),然后到瀏覽器輸入localhost:4000看看。
hexo generate
hexo server
好了,至此,本地博客已經搭建起來了,只是本地哦,別人看不到的。下面,我們要部署到Github。
提交hexo到github步驟
-
注冊Github賬號
已有賬號可以跳過,沒有的,請在此進行注冊,很簡單,這里就不介紹了。
-
創建repository
在自己Github主頁右下角,創建一個新的repository。比如我的Github賬號是imsofter,那么我應該創建的repository名字應該是imsofter.github.io。
-
部署
編輯_config.yml(在H:\hexo下)。你在部署時,要把下面的zippera都換成你的賬號名。
deploy:
type: github
repository: https://github.com/imsofter/imsofter.github.io.git
branch: master
執行下列指令即可完成部署。據說最新版本的hexo 中,這里的 type 要寫成 git,而不是 github。
hexo generate
hexo deploy
記住:每次修改本地文件后,需要hexo generate才能保存。每次使用命令時,都要在H:\hexo目錄下。注意:有些新用戶需要設置 ssh,否則上述命令會失敗。ssh 的介紹和設置方法請看官方教程,不用擔心,很簡單。
Okay,我們的博客已經完全搭建起來了,在瀏覽器訪問zippera.github.io就能看到你的成就了!
以下為安裝出問題的總結
安裝hexo后,bash: hexo: command not found
找到C:\Users\Administrator\AppData\Roaming\npm\node_modules\hexo\bin\,將此目錄添加到環境變量中
執行 hexo deploy 后,出現 error deployer not found:github 的錯誤
hexo 更新到3.0之后,deploy的type 的github需要改成git
repository路徑: http://github.com/imsofter/imsofter.github.io.git (需要將https修改成http)還不行的話嘗試
git@github.com:imsofter/imsofter.github.io.git路徑
改了之后執行npm install hexo-deployer-git --save 安裝hexo對於git的部署工具。
然后再部署試試
驗證報錯報錯verification failed:
Error: Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
解決方法:條件SSHkey
$ ssh-keygen -t rsa -C "imsofter@163.com"
三次回車,即可設置密碼為空
將生成的C:\Users\Administrator.ssh目錄下的id_rsa.pub添加到github上
再測試是否可以連接到github上,
$ ssh git@github.com
Hi imsofter! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.
再可以將代碼推上github上了。
綁定域名
在source目錄下創建CNAME文件
DNS設置
用DNSpod,快,免費,穩定。
注冊DNSpod,添加域名,如下圖設置。
其中A的兩條記錄指向的ip地址是github Pages的提供的ip
192.30.252.153
192.30.252.154