UTF-8なURLを書くとOctpressのページ生成で例外が発生する
本文にURLを入れていると http://tmpurl.com/何か のように、リンク先URLにUTF-8の文字が入っていると、rake generate してもページ生成に失敗します。その時のエラーメッセージは:
unchanged sass/screen.scss
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/maruku-0.6.0/lib/maruku/input/parse_doc.rb:22:in `<top (required)>': iconv will be deprecated in the future, use String#encode instead.
Configuration from ~/_config.yml
Building site: source -> public
~/plugins/raw.rb:11:in `gsub': invalid byte sequence in UTF-8 (ArgumentError)
from ~/plugins/raw.rb:11:in `unwrap'
from ~/plugins/octopress_filters.rb:18:in `post_filter'
from ~/plugins/octopress_filters.rb:33:in `post_render'
from ~/plugins/post_filters.rb:124:in `block in post_render'
from ~/plugins/post_filters.rb:123:in `each'
from ~/plugins/post_filters.rb:123:in `post_render'
from ~/plugins/post_filters.rb:151:in `transform'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/convertible.rb:84:in `do_layout'
from ~/plugins/post_filters.rb:167:in `do_layout'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/post.rb:189:in `render'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:193:in `block in render'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:192:in `each'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:192:in `render'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:40:in `process'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/bin/jekyll:250:in `<top (required)>'
from /usr/local/bin/jekyll:23:in `load'
from /usr/local/bin/jekyll:23:in `<main>'
対処方法は、URLをエンコードしておけばよいです。私は以下のTwitter投稿用ブックマークレットでリンク先をTwitter投稿フォームに表示させて、そのエンコードされたURLを使うことにしました。
javascript:(function()%7Bwindow.twttr=window.twttr%7C%7C%7B%7D;var%20D=550,A=450,C=screen.height,B=screen.width,H=Math.round((B/2)-(D/2)),G=0,F=document,E;if(C%3EA)%7BG=Math.round((C/2)-(A/2))%7Dwindow.twttr.shareWin=window.open('http://twitter.com/share','','left='+H+',top='+G+',width='+D+',height='+A+',personalbar=0,toolbar=0,scrollbars=1,resizable=1');E=F.createElement('script');E.src='http://platform.twitter.com/bookmarklets/share.js?v=1';F.getElementsByTagName('head')%5B0%5D.appendChild(E)%7D());
エラーメッセージからは、どのページがエラー原因なのかが分かりません。原因元の切り分けには、commentやdateなどがある投稿のヘッダにpublished: false
と書いて、そのページを生成対象から外して、エラーが生じるかを見ます。