博客的搭建大致分為以下幾個步驟
- 安裝Node.js
- 安裝Git
- 安裝Hexo
- 安裝主題
- 本地運行測試
- 注冊github并創(chuàng)建倉庫
- 部署到github中去
1、安裝Node.js
安裝
先安裝包管理器brew,參考:
http://www.cnblogs.com/EasonJim/p/6287098.html
有以上前提后,輸入:
brew install node
驗證
node -v
npm -v
更新
//單獨運行
brew update
brew upgrade node
npm install -g npm
//一條運行
brew update && brew upgrade node && npm install -g npm
2、安裝Git
如果安裝上面的步驟安裝了node.js,那么安裝git就只需要在終端輸入下面一句就好了
brew install git
驗證一下
git --version
3、安裝Hexo
安裝Hexo的非常簡單,只要一條命令,前提是安裝好Node.js與Git
npm install -g hexo-cli
初始化,隨便創(chuàng)建一個文件夾,名字隨便取,cd創(chuàng)建的文件夾里面,執(zhí)行下面命令:
hexo init
npm install
本地啟動
hexo g
hexo s
訪問本地鏈接:http://localhost:4000/

4、安裝主題(Next為例)
更多主題查看官網(wǎng)https://hexo.io/themes/
知乎推薦主題https://www.zhihu.com/question/24422335
復(fù)制主題
Hexo 安裝主題的方式非常簡單,只需要將主題文件拷貝至站點目錄的 themes 目錄下, 然后修改下配置文件即可
cd 本地創(chuàng)建的根目錄下
git clone https://github.com/iissnan/hexo-theme-next themes/next
啟用主題
打開根目錄下的_config.yml文件,找到 theme 字段,并將其值更改為 next
theme: next
更改主題外觀
NexT有三個外觀,直接更改主題_config.yml文件的 scheme 參數(shù)即可,如果顯示的是繁體中文,那么站點配置文件中的 language: zh-CN
#scheme: Muse
scheme: Mist
#scheme: Pisces
再執(zhí)行 hexo clean 和 hexo s 就可以在本地預(yù)覽效果了
5、注冊github并創(chuàng)建倉庫
注冊賬戶就不多說了
直接進(jìn)入創(chuàng)建倉庫


配置SSH
為什么要配置這個ssh?
配置SSH 是為了綁定個人電腦與倉庫的關(guān)系,方便之后把博客部署到倉庫中
生成SSH Key
ssh-keygen -t rsa -C 你的郵箱

登錄Github,右上角 頭像 -> Settings —> SSH nd GPG keys —> New SSH key 。把復(fù)制的內(nèi)容粘貼到key中,填好title并點擊 Add SSH key
驗證一下是否成功
ssh -T git@github.com
注意要輸入yes
之后還需要設(shè)置username和email,為了記錄每次提交的記錄
git config --global user.name your name
git config --global user.email your_email@youremail.com
6、部署到github中去
安裝Git部署插件
npm install hexo-deployer-git --save
打開_config.yml文件,在最底部修改部署配置,注意嚴(yán)格的空格
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: git@github.com:youname/youname.github.io.git
branch: master
保存后在終端執(zhí)行以下命令
hexo clean
hexo g
hexo d
部署完成后可在瀏覽器輸入 yourname.github.io 這樣就能看到自己一個屬于自己的博客了,由于github是屬于國外的服務(wù)器,訪問起來有點慢,你也可以部署到coding中去,步驟類似,就不多說了
如果對你有用,歡迎star一下,謝謝!https://github.com/sjxt