是基于Node.js的靜態(tài)Blog搭建工具举塔,結(jié)合
Pages功能,能夠建立一個(gè)自主管理的獨(dú)立博客。下面介紹我是如何建立出這個(gè)網(wǎng)站的。
參考文章:
如何搭建一個(gè)獨(dú)立博客——簡明Github Pages與Hexo教程
1 首先在本地建立并運(yùn)行靜態(tài)blog###
建立一個(gè)文件夾主守,如 H:\Hexo在win文件夾窗口右擊,點(diǎn)擊git bash榄融。之后操作推薦全部用命令行参淫。
$ npm install -g hexo #安裝Hexo
$ hexo init #在H:\Hexo 文件夾生成blog模板
$ hexo g #生成靜態(tài)blog == hexo generate
$ hexo s #在本地運(yùn)行服務(wù)器 == hexo server
就可以看到初始的靜態(tài)Blog:Helloworld
如果想要寫一篇以“new_post_name”為名的新文章,則輸入
$ hexo n "new_post_name"
會(huì)在\source\_posts下生成new_post_name.md的Markdown文件囚枪,編輯此文件寫文章桌吃。
當(dāng)然可以直接在\source\_posts新建*.md文件
重新運(yùn)行:
$ hexo g
$ hexo s
就可以看到新加文章
2 將建立的靜態(tài)Blog push到Github上去###
首先你得有一個(gè)Github賬戶溪食,申請(qǐng)過程忽略
其次在本地配置SSH 公鑰
如果郵件地址是youremail@youremail.com
生成新的SSH Key:
$ ssh-keygen -t rsa -C "youremail@youremail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/your_user_directory/.ssh/id_rsa):
直接回車谍倦,
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
輸入密碼耍铜,生成SSH Key
- 將SSH 公鑰輸入Github網(wǎng)站
打開 /Users/your_user_directory/.ssh/id_rsa.pub
將里面的密鑰復(fù)制
打開Github網(wǎng)站邑闺,登陸,進(jìn)入Account Settings--->SSH Public keys ---> add another public keys,點(diǎn)擊add key棕兼,將復(fù)制的密鑰粘貼進(jìn)去
可以通過 ssh -T git@githubcom看看設(shè)置是否成功
The authenticity of host 'github.com (207.97.227.239)' can't be established.
RSA key fingerprint is 6:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?yes
Hi ! You've successfully authenticated, but GitHub does not provide shell access.
還需要配置用戶名陡舅,郵箱
$ git config --global user.name "yourname"
$ git config --global user.email "youremail@youremail.com"
目前本地git配置完成。
接著伴挚,需要在Github網(wǎng)站上建立一個(gè)項(xiàng)目Repository靶衍。
Github上只有Pages項(xiàng)目才能輸出為Html。我們可以把pages放在一個(gè)項(xiàng)目中茎芋,也可以新建一個(gè)
yourname.github.io
的項(xiàng)目颅眶,分支選擇ph-pages,訪問yourname.github.io就可以田弥。
我們點(diǎn)擊New Repository,新建一個(gè)代碼倉庫涛酗,我的名稱就寫jcjview.github.io
在setting里選擇
SSH URL
(當(dāng)然也可以用HTTPS,但這樣配置的SSH密鑰就白配置了)
復(fù)制出來偷厦,
git@github.com:yourname/yourname.github.io.git
我的就是git@github.com:jcjview/jcjview.github.io.git
將項(xiàng)目的branch添加一個(gè)ph-pages,這樣訪問
才能顯示網(wǎng)頁
在hexo文件夾根目錄下商叹,打開_config.yml文件,修改最后的deploy字段:
deploy:
type: github
repository: git@github.com:yourname/yourname.github.io.git
branch: master
配置好后沪哺,就可以上傳了
$ hexo d # hexo deploy
3 修改主題###
默認(rèn)的主題比較單調(diào)沈自,而且沒有sitemap,評(píng)論等功能辜妓,需要修改主題文件來添加枯途。
(待續(xù))
4 購買配置域名###
(待續(xù))