diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/category_generator.rb | 3 | ||||
-rw-r--r-- | plugins/code_block.rb | 2 | ||||
-rw-r--r-- | plugins/gist_tag.rb | 35 | ||||
-rw-r--r-- | plugins/include_code.rb | 2 |
4 files changed, 29 insertions, 13 deletions
diff --git a/plugins/category_generator.rb b/plugins/category_generator.rb index a49c4296..c55d62f4 100644 --- a/plugins/category_generator.rb +++ b/plugins/category_generator.rb @@ -119,7 +119,7 @@ module Jekyll =============================================== Error for category_generator.rb plugin ----------------------------------------------- - No 'category_index.hmtl' in source/_layouts/ + No 'category_index.html' in source/_layouts/ Perhaps you haven't installed a theme yet. =============================================== @@ -191,4 +191,3 @@ ERR end end - diff --git a/plugins/code_block.rb b/plugins/code_block.rb index c70e181e..46620d86 100644 --- a/plugins/code_block.rb +++ b/plugins/code_block.rb @@ -79,7 +79,7 @@ module Jekyll source = "<figure class='code'>" source += @caption if @caption if @filetype - source += " #{highlight(code, @filetype)}</figure>" + source += "#{highlight(code, @filetype)}</figure>" else source += "#{tableize_code(code.lstrip.rstrip.gsub(/</,'<'))}</figure>" end diff --git a/plugins/gist_tag.rb b/plugins/gist_tag.rb index 16203450..0828d270 100644 --- a/plugins/gist_tag.rb +++ b/plugins/gist_tag.rb @@ -46,7 +46,7 @@ module Jekyll end def get_gist_url_for(gist, file) - "https://raw.github.com/gist/#{gist}/#{file}" + "https://gist.github.com/raw/#{gist}/#{file}" end def cache(gist, file, data) @@ -71,8 +71,31 @@ module Jekyll end def get_gist_from_web(gist, file) - gist_url = get_gist_url_for gist, file - raw_uri = URI.parse gist_url + gist_url = get_gist_url_for(gist, file) + data = get_web_content(gist_url) + + if data.code.to_i == 302 + data = handle_gist_redirecting(data) + end + + if data.code.to_i != 200 + raise RuntimeError, "Gist replied with #{data.code} for #{gist_url}" + end + + cache(gist, file, data.body) unless @cache_disabled + data.body + end + + def handle_gist_redirecting(data) + redirected_url = data.header['Location'] + if redirected_url.nil? || redirected_url.empty? + raise ArgumentError, "GitHub replied with a 302 but didn't provide a location in the response headers." + end + get_web_content(redirected_url) + end + + def get_web_content(url) + raw_uri = URI.parse url proxy = ENV['http_proxy'] if proxy proxy_uri = URI.parse(proxy) @@ -84,12 +107,6 @@ module Jekyll https.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new raw_uri.request_uri data = https.request request - if data.code.to_i != 200 - raise RuntimeError, "Gist replied with #{data.code} for #{gist_url}" - end - data = data.body - cache gist, file, data unless @cache_disabled - data end end diff --git a/plugins/include_code.rb b/plugins/include_code.rb index 220466b6..41f30337 100644 --- a/plugins/include_code.rb +++ b/plugins/include_code.rb @@ -62,7 +62,7 @@ module Jekyll title = @title ? "#{@title} (#{file.basename})" : file.basename url = "/#{code_dir}/#{@file}" source = "<figure class='code'><figcaption><span>#{title}</span> <a href='#{url}'>download</a></figcaption>\n" - source += " #{highlight(code, @filetype)}</figure>" + source += "#{highlight(code, @filetype)}</figure>" safe_wrap(source) end end |