在Mac上從零開始搭建基於Github的Octopress博客

Octopress
Github

css

經過網絡幾篇文章整理的大體全面的教程。html

1.安裝Octopress

確保安裝了gitruby1.9.3,經過brew安裝rbenv而後用rbenv安裝rubygit

安裝brew

先卸載MacPortsgithub

sudo prot -f uninstall installed
sudo rm -fr \

再安裝brewshell

curl -L http://github.com/mxcl/homebrew/tarball/master | tar xz –strip 1 -C /usr/local

export PATH=/usr/local/bin:$PATH

安裝成功後經過brew install查看brew版本ubuntu

安裝ruby

brew install rbenv
brew install ruby-build
rbenv install 1.9.3-p0
rbenv rehash

最後安裝Octopress

git clone git://github.com/imathis/octopress.git octopress

cd octopress
gem install bundler
rbenv rehash
bundle install
rake install

配置Octopress

編輯 config.yml文件的url,title,subtitle,author瀏覽器

最好把裏面的twitter相關的信息所有刪掉,不然因爲GFW的緣由,將會形成頁面load很慢。同理,修改定製文件/source/_includes/custom/head.html 把google的自定義字體去掉。sass

安裝支持新浪微博和Dribbble的Octopress的Greyshade主題

我如今用的就是greyshade主題 http://www.sgxiang.comruby

cd octopress

 git clone git@github.com:allenhsu/greyshade.git .themes/greyshade

 echo "\$greyshade: color;" >> sass/custom/_colors.scss //替換 color 爲自定義的連接高亮顏色

 rake "install[greyshade]"

在_config.yml中加入markdown

weibo_user: xsxiang # 微博數字 ID 或域名 ID
dribbble_user: 
weibo_share: true # 是否開啓微博分享按鈕

關於greyshade主題的頭像問題,有兩種途徑能夠設置頭像

  • 在_config.yml文件中設置一個email,而後到gravatar網站上添加該email並上傳一張頭像
  • 將須要使用的圖片放到/source/images下。而後把/source/_includes/header.html文件中的img替換成 《img alt=「Profile Picture」 src=「/images/tx.png」 style=「width:160px;」》

配置Disqus插件

Disqus是octopress內置的comments功能,編輯config.yml文件能夠打開該功能,找到如下內容修改

#Disqus comments
disqus_short_name: 
disqus_show_comment_count: false

填入註冊disqus帳號的名稱,並將false修改成true。【disqus要和本身的username.github.com關聯上】

2.配置github相關

在本機建立ssh

cd ~/.ssh
ssh-keygen -t rsa -C 你註冊github時的email

彈出Enter file in which to save the key (/Users/twer/.ssh/id_rsa):直接按空格

彈出Enter passphrase (empty for no passphrase):輸入你github帳號的密碼。Enter same passphrase again:再次輸入你的密碼。

打開~/.ssh下的id_rsa.pub文件複製裏面的所有內容。
登錄github,選擇Account Settings-->SSH Public Keys 添加ssh,把剪切板的內容複製到key輸入框內直接保存。

測試shh:

ssh git@github.com

輸出

PTY allocation request failed on channel 0
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

表明成功

創建一個倉庫

登錄github建立一個倉庫 ,倉庫名稱爲username.github.com好比個人是sgxiang.github.com

3.部署博客到github

利用octopress的一個配置rake任務來自動配置上面建立的倉庫:可讓咱們方便的部署GitHub page。在終端輸入以下命令:

rake setup_github_pages

彈出以後輸入git@github.com:your_username/your_username.github.com.git不要用提示的io,個人是git@github.com/sgxiang/sgxiang.github.com.git

輸入如下命令部署博客

rake generate
rake deploy

若是沒法push到倉庫的master分支,嘗試在項目目錄的.git/config中添加

[branch "master"]
 remote = origin
 merge = refs/heads/master

博客的source須要單獨提交,執行以下命令就能夠將source提交到倉庫的source分支下

git add .
git commit -m 'Initial source commit'
git push origin source

部署前能夠在本地預覽,輸入rake preview以後在瀏覽器輸入http://localhost:4000/來訪問

4.寫博客

經過命令

rake new_post["myTitle"]

文章生成在目錄下的source/_posts目錄下。文章是markdown格式的。能夠經過 Mou 軟件來編輯保存。

關於markdown的格式能夠參考這篇文章:http://wowubuntu.com/markdown/

寫完後就能夠部署更新文章到github上了

rake generate
git add .
git commit -am "Some comment here." 
git push origin source
rake deploy

參考文章

相關文章
相關標籤/搜索