從零到一百 ~ 在 Windows上使用 Octopress
使用平台:Win7 32bit
[Github]
- 申請Github帳號
-
建立Github pages (使用 Automatic Page Generator)
=> New repository
=> Repository name的地方打 你想要的github page網址 (像我就是打marsw.github.com)
=> Create repository
=> 進入該repository頁面,選擇admin
=> Automatic Page Generator
=> Continue to Layouts
=> PUBLIS之後會收到信,大概要10分鐘,Github Page就會產生好囉!
Github ssh key
打開windows command line
ssh-keygen -C "username@email.com" -t rsa
照著上面的指示,輸入密碼或跳過設定密碼。
/USER/.ssh中存放著成對的key
- id_rsa.pub : public key
- id_rsa : private key (請小心保存)
複製public key(小心不要複製到空格)貼到github帳號中的SSH Public Keys欄位
延伸:git教學
[Install Ruby]
-
下載 RubyInstaller(已包含Gem) 和 Development Kit
- 解壓縮 Development Kit
-
到 Development Kit 資料夾底下下指令 (cmd)
cd C:\Devkit ruby dk.rb init #產生 config.yaml,裡面有你的 ruby 路徑,一般會幫你設好 ruby dk.rb install
-
保險起見,更新一下gem
gem update --system gem update
[Install Git]
下載 Git ,並安裝
[Setup Octopress]
-
開啟Git
git clone git://github.com/imathis/octopress.git octopress cd octopress gem install bundler bundle install # 安裝 Gemfile 檔案中所列的 gems rake install # 安裝預設的 Octopress 樣式
-
讓Octopress支援中文
set LANG=zh_TW.UTF-8 set LC_ALL=zh_TW.UTF-8
-
設定 Blog 放到GitHub Page上
rake setup_github_pages #按下enter後會要你輸入url
git@github.com:MarsW/marsw.github.com.git #MarsW是我的帳戶名稱,後面是我專案名稱 rake generate #產生網站檔案 rake deploy #發佈到github
預覽
rake preview #在本機開port 4000 的 web server
就可以在 http://127.0.0.1:4000/ 看到預覽畫面
- 修改 Octopress 設定
修改_config.yml 設定參數
[安裝時遇到的問題]
-
下指令
rake setup_github_pages
,噴出錯誤訊息rake aborted! You have already activated rake 10.0.2, but your Gemfile requires rake 0.9.2.2. Using bundle exec may solve this. c:/Users/MarsW/octopress/Rakefile:2:in `<top (required)>' (See full trace by running task with --trace)
更改Gemfile (在/USER/octopress中)
修改成gem 'rake', '~> 10.0.2'
-
下指令
rake deploy
,噴出錯誤訊息error: src refspec master does not match any. error: failed to push some refs to 'git@github.com:MarsW/marsw.github.com.git'
輸入
git config --global user.email "你github的email"
輸入git config --global user.name "你github的帳號"
[Reference]
不歸錄 在 Windows 使用 Octopress Programming Design Notes 在 Windows 設定 Octopress 雨蒼的終端機 使用Git與Github管理軟體開發專案
在Octopress裡面寫文章不像一般blog有帳號登入的頁面,
每篇文章就是一個markdown檔,就像以前開啟記事本或word一樣,
打完之後下個指令把markdown轉成html,然後上傳這樣。
[建立新文章]
打開Git
cd octopress
rake new_post["文章標題"]
[編輯文章]
不管是新建立、或是修改之前的文章,
在資料夾source/_posts/,可以看到建立的文件日期-標題.markdown
想刪除文章也是在此直接delete掉檔案就好
打開自己習慣用的markdown編輯器,就可以編寫文章囉
個人用的是MarkdownPad或notepad++
markdown語法教學
[上傳文章]
不管是更改Octopress設定、編輯文章、刪除文章...這些變動
所要做的就是,打開Git
cd octopress
rake generate #產生網站檔案
rake deploy #發佈到github
[上傳文章時遇到的問題]
-
下指令
rake generate
,噴出一長串錯誤## Generating Site with Jekyll unchanged sass/screen.scss c:/Ruby193/lib/ruby/gems/1.9.1/gems/maruku-0.6.0/lib/maruku/input/parse_doc.rb:2 2:in `<top (required)>': iconv will be deprecated in the future, use String#enco de instead. Configuration from c:/Users/MarsW/octopress/_config.yml Building site: source -> public c:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/convertible.rb:29:in `read_yaml': invalid byte sequence in CP950 (ArgumentError) from c:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/post.rb:39:in `initialize' from c:/Users/MarsW/octopress/plugins/preview_unpublished.rb:23:in `new' from c:/Users/MarsW/octopress/plugins/preview_unpublished.rb:23:in `block in read_posts' from c:/Users/MarsW/octopress/plugins/preview_unpublished.rb:21:in `each' from c:/Users/MarsW/octopress/plugins/preview_unpublished.rb:21:in `read_posts' from c:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:128:in `read_directories' from c:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:98:in `read' from c:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:38:in `process' from c:/Ruby193/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/bin/jekyll:250:in`<top (required)>' from c:/Ruby193/bin/jekyll:23:in `load' from c:/Ruby193/bin/jekyll:23:in `<main>'
- 修改
C:\ruby193\lib\ruby\gems\1.9.1\gems\jekyll-0.11.0\lib\jekyll\convertible.rb
def read_yaml(base, name)
self.content = File.read(File.join(base, name))
if self.content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
self.content = $POSTMATCH
begin
self.data = YAML.load($1)
rescue => e
puts "YAML Exception reading #{name}: #{e.message}"
end
end
將
self.content = File.read(File.join(base, name))
修改為
self.content = File.read(File.join(base, name), :encoding => “utf-8”)
- 確認文章編碼為UTF-8(無BOM)
MarkdownPad本身存檔就是UTF-8(無BOM),notepad++要調編碼
[Reference]
高見龍 How to Install Octopress on Heroku Larry's Blog win建立Octopress無法使用中文?