前提:
1.新建一個github倉庫
2.安裝配置Node.js
3.安裝配置Git
前提
步驟1.新建一個github倉庫
注:==倉庫名稱要求,yourname.github.io;==
勾選Initialize this repository with a README;
- 新建完成後打開倉庫,點擊右側settings按鈕,開啓下面的GitHub Pages;
- Source保存爲master branch,上面的鏈接是之後博客訪問的鏈接
步驟2.安裝Node.js
打開Node.js官網下載對應操作系統版本及位數的node.js
安裝完成後可通過以下命令驗證是否已配置成功(默認安裝已自動配置環境變量)
node -v npm -v
步驟3.安裝git
打開Git官網下載對應操作系統版本及位數的git
安裝完成後可通過一下命令驗證是否配置成功(默認安裝已自動配置環境變量,即選擇use Git from the Windows Command Prompt)
git --version
配置git
鼠標右鍵打開git bash here(以下命令都是在git bash下執行)
設置git的user name和email(第一次使用)
git config --global user.name "yourname" git config --global user.email "youremail"
配置ssh
#生成密鑰,默認存儲路徑:C:\User\Administrator\.ssh ssh-keygen -t rsa -C"youremail" #添加密鑰到ssh-agent eval "$(ssh-agent -s)" #添加生成的SSH key到ssh-agent ssh -add ~/.ssh/id_rsa
在github上添加ssh key.
#步驟1 登錄github,點擊頭像下的settings #步驟2 打開左側的SSH and GPG keys #步驟3 點擊右側的new SSH key #步驟4 Title 自定義 Key輸入剛纔生成的C:\User\Administrator\.ssh路徑下的id_rsa.pub
驗證ssh是否添加成功
ssh -T [email protected]
ssh-key配置失敗解決方法
首先,清除所有的key-pair ssh-add -D rm -r ~/.ssh 刪除你在github中的public-key 重新生成ssh密鑰對 ssh-keygen -t rsa -C "[email protected]" 接下來正常操作 在github上添加公鑰public-key: 1、首先在你的終端運行 xclip -sel c ~/.ssh/id_rsa.pub將公鑰內容複製到剪切板 2、在github上添加公鑰時,直接複製即可 3、保存
小試牛刀
hexo+github設置
安裝Hexo
找到一個合適的位置創建一個新的文件夾,必須是空的。實例文件夾:D:\Blog
打開cmd,進入新建的文件
d: cd Blog
安裝hexo
npm install hexo -g
驗證是否安裝成功
hexo -v
配置Hexo
初始化Blog文件夾
hexo init
安裝必要的組件
npm install
生成目錄結構
hexo g #或 hexo generate
開啓hexo服務,預覽界面
hexo s #或 hexo server
第一次訪問
訪問:localhost:4000,可看到加載的頁面。
Hexo聯繫Github
打開hexo配置文件;D:\Blog\_config.yml
文件末尾處配置:
repository:打開github倉庫點擊Clone or download,複製裏面ssh對應的倉庫地址;
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repository: [email protected]:username/username.github.io.git
branch: master