diff options
author | Parker Moore <parkrmoore@gmail.com> | 2013-10-05 20:48:23 -0400 |
---|---|---|
committer | Parker Moore <parkrmoore@gmail.com> | 2013-10-05 20:48:23 -0400 |
commit | 6a7cced3aac70847dd4f47e785a50c134571d6cd (patch) | |
tree | a5a86ef74a786420a937222a81880f578745f7c0 /plugins | |
parent | 8aa851e9e342fac787215988ede20dcb0b046a22 (diff) | |
parent | cbf4b6570f4e999b69ffdaad7057d5a51213bd1e (diff) | |
download | my_new_personal_website-6a7cced3aac70847dd4f47e785a50c134571d6cd.tar.xz my_new_personal_website-6a7cced3aac70847dd4f47e785a50c134571d6cd.zip |
Merge branch 'fix-gist-plugin' of git://github.com/aleiphoenix/octopress into aleiphoenix-fix-gist-plugin
* 'fix-gist-plugin' of git://github.com/aleiphoenix/octopress:
fix old style gist url not found issue
Diffstat (limited to '')
-rw-r--r-- | plugins/gist_tag.rb | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/plugins/gist_tag.rb b/plugins/gist_tag.rb index 16203450..62c490d0 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) @@ -72,7 +72,29 @@ module Jekyll def get_gist_from_web(gist, file) gist_url = get_gist_url_for gist, file - raw_uri = URI.parse gist_url + data = get_web_content gist_url + data = handle_gist_redirecting data + 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 + + def handle_gist_redirecting(data) + if data.code.to_i == 302 + redirected_url = data.header['Location'] + data = get_web_content redirected_url + if data.code.to_i != 200 + raise RuntimeError, "Gist replied with #{data.code} for #{gist_url}" + end + end + data + end + + def get_web_content(url) + raw_uri = URI.parse url proxy = ENV['http_proxy'] if proxy proxy_uri = URI.parse(proxy) @@ -84,12 +106,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 |