1. 程式人生 > >二、Hexo+Github搭建自己的部落格

二、Hexo+Github搭建自己的部落格

  • 1.安裝Node.js,配置環境變數(注意node版本,好多問題在於node版本,我用的v10.5.0)
  • 2.安裝git環境配置git環境
  • 3.github新建倉庫,格式為:賬戶名.github.io,需要勾選Initialize this repository with a README
  • 4.安裝hexo
    新建資料夾,命令:npm install hexo -g,開始安裝Hexo
    命令:hexo -v,檢查是否安裝成功
    命令:hexo init,初始化該資料夾(“Start blogging with Hexo!”表示初始化成功)
    命令:npm install,安裝所需要的元件
    命令:hexo g,首次體驗Hexo
    命令:hexo s,開啟伺服器,訪問該網址,localhost:4000(預設埠4000)------假如遇到問題,可能埠被佔用,可通過命令:“hexo server -p 埠號”改變埠
    
  • 5.將Hexo和Github聯絡(需要使用Git Bash)

    命令:git config --global user.name "git名字"
    命令:git config --global user.email "自己郵箱"
    命令:ssh-keygen -t rsa -C “自己郵箱”(注意:命令:cd ~/.ssh可以檢查是否存在.ssh資料夾),連續三次回車,生成金鑰
    輸入eval "$(ssh-agent -s)",新增金鑰到ssh-agent,再輸入ssh-add ~/.ssh/id_rsa,新增生成的SSH key到ssh-agent
    登入github下settings,新增ssh
    命令:ssh -T 
    [email protected]
    ,測試新增ssh是否成功(看到後面自己使用者名稱說明成功) 配置Deployment,在其資料夾中,找到_config.yml檔案修改deploy,下面有三個子屬性,type、repository、branch,repository輸入自己git上專案連結
  • 6.新建部落格,命令:hexo new post “部落格名”

  • 7.安裝拓展,命令:npm install hexo-deployer-git –save
  • 8.生成的文章在source/_posts中,編輯好之後,命令:hexo d -g,生成以及部署,成功後訪問http://使用者名稱.github.io,即可看到效果