From cbf4b6570f4e999b69ffdaad7057d5a51213bd1e Mon Sep 17 00:00:00 2001 From: AR Date: Sun, 15 Sep 2013 21:56:22 +0800 Subject: [PATCH 1/5] fix old style gist url not found issue --- plugins/gist_tag.rb | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/plugins/gist_tag.rb b/plugins/gist_tag.rb index 1620345..62c490d 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 From 4cc76820331b2b327c03d27216e79bc55a58c505 Mon Sep 17 00:00:00 2001 From: Trey Hunner Date: Sun, 29 Sep 2013 22:21:44 -0400 Subject: [PATCH 2/5] Add proper disqus identifier comment count links Fixes #277 --- .themes/classic/source/_includes/article.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.themes/classic/source/_includes/article.html b/.themes/classic/source/_includes/article.html index 23f4884..8427997 100644 --- a/.themes/classic/source/_includes/article.html +++ b/.themes/classic/source/_includes/article.html @@ -9,7 +9,8 @@

{% include post/date.html %}{{ time }} {% if site.disqus_short_name and page.comments != false and post.comments != false and site.disqus_show_comment_count == true %} - | Comments + | Comments {% endif %}

{% endunless %} From 0a1b94d222d899868e1c3a8d3518c434e909e2f1 Mon Sep 17 00:00:00 2001 From: Alexandre Perrin Date: Thu, 3 Oct 2013 10:00:27 +0200 Subject: [PATCH 3/5] Fix Disqus over https. Forcing http:// as protocol will make Disqus fail when server over https for security reasons. --- .themes/classic/source/_includes/disqus.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.themes/classic/source/_includes/disqus.html b/.themes/classic/source/_includes/disqus.html index eb30877..549ba3d 100644 --- a/.themes/classic/source/_includes/disqus.html +++ b/.themes/classic/source/_includes/disqus.html @@ -14,7 +14,7 @@ {% endif %} (function () { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; - dsq.src = 'http://' + disqus_shortname + '.disqus.com/' + disqus_script; + dsq.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + disqus_shortname + '.disqus.com/' + disqus_script; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); }()); From e692d8ea1a242e385bfcbd49e28d8b4fd9392661 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 5 Oct 2013 20:52:12 -0400 Subject: [PATCH 4/5] Clean up Gist redirection. --- plugins/gist_tag.rb | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/plugins/gist_tag.rb b/plugins/gist_tag.rb index 62c490d..f5123cb 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) From f43163b9b781a2ccc300a7215e948a352a96e341 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 5 Oct 2013 20:57:03 -0400 Subject: [PATCH 5/5] Error handling FTW --- plugins/gist_tag.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/gist_tag.rb b/plugins/gist_tag.rb index f5123cb..0828d27 100644 --- a/plugins/gist_tag.rb +++ b/plugins/gist_tag.rb @@ -88,6 +88,9 @@ module Jekyll 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