Clean up Gist redirection.

main
Parker Moore 12 years ago
parent 6a7cced3aa
commit e692d8ea1a

@ -71,26 +71,24 @@ module Jekyll
end end
def get_gist_from_web(gist, file) def get_gist_from_web(gist, file)
gist_url = get_gist_url_for gist, file gist_url = get_gist_url_for(gist, file)
data = get_web_content gist_url data = get_web_content(gist_url)
data = handle_gist_redirecting data
if data.code.to_i == 302
data = handle_gist_redirecting(data)
end
if data.code.to_i != 200 if data.code.to_i != 200
raise RuntimeError, "Gist replied with #{data.code} for #{gist_url}" raise RuntimeError, "Gist replied with #{data.code} for #{gist_url}"
end end
data = data.body
cache gist, file, data unless @cache_disabled cache(gist, file, data.body) unless @cache_disabled
data data.body
end end
def handle_gist_redirecting(data) def handle_gist_redirecting(data)
if data.code.to_i == 302
redirected_url = data.header['Location'] redirected_url = data.header['Location']
data = get_web_content redirected_url 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 end
def get_web_content(url) def get_web_content(url)

Loading…
Cancel
Save