From e692d8ea1a242e385bfcbd49e28d8b4fd9392661 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 5 Oct 2013 20:52:12 -0400 Subject: Clean up Gist redirection. --- plugins/gist_tag.rb | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'plugins') diff --git a/plugins/gist_tag.rb b/plugins/gist_tag.rb index 62c490d0..f5123cb9 100644 --- a/plugins/gist_tag.rb +++ b/plugins/gist_tag.rb @@ -71,26 +71,24 @@ module Jekyll end def get_gist_from_web(gist, file) - gist_url = get_gist_url_for gist, file - data = get_web_content gist_url - data = handle_gist_redirecting data + 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 - data = data.body - cache gist, file, data unless @cache_disabled - data + + cache(gist, file, data.body) unless @cache_disabled + data.body 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 + redirected_url = data.header['Location'] + get_web_content(redirected_url) end def get_web_content(url) -- cgit v1.2.1