利用github pages與jekyll搭建個(gè)人博客(一):基礎(chǔ)環(huán)境配置與博客搭建
利用github pages與jekyll搭建個(gè)人博客(二):添加分頁功能以及安裝Grunt
查看github上源碼
github博客地址
第一步邮府,配置jekyll環(huán)境
因?yàn)楸救擞玫氖莔ac系統(tǒng),以下操作都基于此间狂。
1.安裝ruby
2.安裝RubyGems
npm install rubygems
gem -v //2.0.14.1
3.安裝jekyll
gem install jekyll
//報(bào)錯(cuò)乡数,說
Fetching: jekyll-3.4.0.gem (100%)
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
//所以之后的操作都使用sudo
sudo gem install jekyll //安裝成功
jekyll -v //查看版本
- 后來幫同事安裝的時(shí)候站削,發(fā)現(xiàn)
sudo gem install jekyll
有其他的報(bào)錯(cuò)勋乾,原因是ruby版本過低蛛淋,所以要先升級(jí)ruby唧躲,然后再安裝jekyll
- 如果是之前安裝好的環(huán)境造挽,日后運(yùn)行時(shí)報(bào):
jekyll 3.4.0 | Error: uninitialized constant Bundler::Plugin::API::Source
需要升級(jí)gem
sudo gem update //升級(jí)gem
第二步,使用jekyll創(chuàng)建博客目錄
jekyll new myblog //創(chuàng)建博客目錄
//報(bào)錯(cuò)
Dependency Error: Yikes! It looks like you don't have bundler or one
of its dependencies installed. In order to use Jekyll as currently
configured, you'll need to install this gem. The full error message
from Ruby is: 'cannot load such file -- bundler' If you run into trouble,
you can find helpful resources at https://jekyllrb.com/help/!
jekyll 3.4.0 | Error: bundler
此時(shí)需要安裝bundler弄痹,總之就是缺什么饭入,裝什么
sudo gem install bundler
rm -rf myblog //刪除剛才生成的文件夾,重新生成
jekyll new blog
cd blog
jekyll serve //啟動(dòng)服務(wù)
此時(shí)肛真,打開瀏覽器谐丢,輸入localhost:4000 就可以看到我們的博客了
當(dāng)然,在啟動(dòng)服務(wù)的時(shí)候如果遇到以下這個(gè)錯(cuò)誤
D:\GarryBlog>jekyll server
Configuration file: D:/GarryBlog/_config.yml
Configuration file: D:/GarryBlog/_config.yml
Source: D:/GarryBlog
Destination: D:/GarryBlog/_site
Incremental build: disabled. Enable with --incremental
Generating...
done in 0.252 seconds.
Please add the following to your Gemfile to avoid polling for changes:
gem 'wdm', '>= 0.1.0' if Gem.win_platform?
Auto-regeneration: enabled for 'D:/GarryBlog'
Configuration file: D:/GarryBlog/_config.yml
jekyll 3.3.1 | Error: Permission denied - bind(2) for 127.0.0.1:4000
這個(gè)錯(cuò)誤是告訴我們4000端口被占用蚓让,解決方法是:在_config.yml文件的末尾加上port: 4040乾忱,改為4040端口即可。這樣在瀏覽器中輸入http://127.0.0.1:4040 也可以看到我們的博客了历极。
第三步窄瘟,將簡書上的文章打包下載,替換_posts目錄中的文件
打包下載的文件:
現(xiàn)在趟卸,將文件名更改date-title.md
蹄葱,如:2016-10-13-圖片上下居中.md
,操作結(jié)束后刷新頁面衰腌,可以看到頁面上已經(jīng)更改為自己當(dāng)前的文章列表了新蟆。
第四步
在根目錄下創(chuàng)建_layouts目錄,并創(chuàng)建子文件:default.html
在根目錄下創(chuàng)建index.html文件
保存文件右蕊,刷新頁面
但是蠻奇怪的是我的頁面好像沒有變動(dòng),還是這個(gè)樣子吮螺,不知道是哪一步出了問題
上面的問題已解決:
在第二步j(luò)ekyll new myblog之后會(huì)自動(dòng)創(chuàng)建一個(gè)index.md的文件饶囚,將該文件刪除或者內(nèi)容清空,頁面就會(huì)根據(jù)Index.html顯示
在此鸠补,我選擇將該文件刪除萝风,下面是index.md中的內(nèi)容
---
# You don't need to edit this file, it's empty on purpose.
# Edit theme's home layout instead if you wanna make some changes
# See: https://jekyllrb.com/docs/themes/#overriding-theme-defaults
layout: home
---
第五步,在自己的github上創(chuàng)建博客項(xiàng)目
在自己的github上創(chuàng)建目錄blog紫岩,然后克隆到本地规惰,新切分支:
git clone *****
git checkout -b gh-page
再將之前文件夾里的內(nèi)容全部拷貝到blog目錄中,然后提交代碼:
git add .
git commit -am "個(gè)人博客基礎(chǔ)搭建"
git push origin gh-pages:gh-pages //將本地gh-pages分支推送到遠(yuǎn)端
注意泉蝌,這里我使用的目錄名blog與github的用戶名不一致歇万,所以需要切分支gh-pages揩晴,因?yàn)間ithub規(guī)定只有g(shù)h-pages分支中的頁面,才會(huì)生成網(wǎng)頁文件贪磺。
此時(shí)博客地址:https://username.github.io/blog/
當(dāng)然硫兰,也可以在創(chuàng)建目錄時(shí),將目錄名與用戶名一致寒锚,這樣就不需要?jiǎng)?chuàng)建gh-pages分支了劫映,直接在master中提交就可以生成網(wǎng)頁文件了
此時(shí)博客地址:https://username.github.io/
另外:
github上的博客可以自己創(chuàng)建,也可以fork別人的博客代碼刹前,進(jìn)行改造泳赋,這里初次創(chuàng)建,先自己創(chuàng)建喇喉,后期fork別人的代碼或者直接下一些簡潔的模板摹蘑,改成自己想要的樣子。
ps:
利用github pages與jekyll搭建個(gè)人博客(一):基礎(chǔ)環(huán)境配置與博客搭建
利用github pages與jekyll搭建個(gè)人博客(二):添加分頁功能以及安裝Grunt
查看github上源碼
github博客地址