1. 程式人生 > >Hexo+git建站流程及注意事項

Hexo+git建站流程及注意事項

建站基本流程

1、安裝nodejsgit
2、安裝hexo

$ npm install -g hexo-cli

3、建站,folder為站點資料夾名稱

$ hexo init <folder>
$ cd <folder>
$ npm install

4、 本地試執行

$ git clean //清除原有伺服器資料
$ git generate //生成靜態檔案,可簡寫為 git g
$ git server //啟動本地服務

啟動伺服器後,預設情況下本地訪問網址為: http://localhost:4000/

注意:網站資訊配置參考官網 hexo


釋出文章

$ hexo new post <title>

使用上述命令釋出新文章後,會在/source/_posts 資料夾下生成以 <title> 命名的 .md檔案,在該檔案中編輯文章內容。

如何引用本地圖片?

1、 將 _config.yml 配置檔案中的 post_asset_folder 項修改為 true;
2、修改上述屬性後,再次執行釋出文章命令,在生成以 <title> 命名的 md. 檔案的同時,還會生成同名資料夾,將需要引用的圖片放在此資料夾中;
3、通過如下語法在 .md 檔案中引用圖片

{% asset_img 圖片名稱.jpg 圖片的說明 %}


部署到github

1、註冊github賬號,並新建倉庫,注意,倉庫名必須與賬號名相同
2、修改 _config.yml 配置檔案中的部署引數

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: git
  repo: [email protected].com:flyoob/flyoob.github.io.git //github倉庫地址
  branch: master

3、為 Hexo 安裝 Git 外掛

npm install hexo-deployer-git
--save

4、部署命令

$ hexo deploy
$ hexo d

部署成功後即可通過網址 https://username.github.io/ https://jiajiaaz.github.io/ 訪問部落格主頁。

注意:

如果本地的git還未曾與 github建立連線,則需要初始化使用者資訊並驗證 ssh key 以建立連線。
配置使用者身份資訊:

 $ git config --global user.name "JiajiaAz"
 $ git config --global user.email "[email protected]"

生成祕鑰:

$ ssh-keygen -t rsa -C "[email protected]"

連續三個回車後生成金鑰,儲存在:C:\Users\Administrator.sshid_rsa.pub 檔案中。複製祕鑰,並貼上到github的ssh key 選中。
驗證祕鑰是否新增成功:

$ ssh -T git@github.com


更換主題

1、挑選到合適的主題後,複製其github地址,並將其克隆到themes資料夾下;
2、將 _config.yml 配置檔案中的theme 屬性修改為新的主題名。

“cannot get/xxx”的解決辦法

部落格搭建好後,在點選某些選單時,遇到 “cannot get/xxx”的問題,例如,在點選 About 選單時,彈出的頁面顯示 “cannot get/about/”。這是因為沒有初始化 about目錄,可通過以下命令解決:

$ hexo new page "about"