Skip to content

Instantly share code, notes, and snippets.

@cyfdecyf
Created December 13, 2011 07:20
Show Gist options
  • Save cyfdecyf/1471046 to your computer and use it in GitHub Desktop.
Save cyfdecyf/1471046 to your computer and use it in GitHub Desktop.
Liquid filter to downcase encoded url
diff --git a/plugins/octopress_filters.rb b/plugins/octopress_filters.rb
index a5bb235..928333b 100644
--- a/plugins/octopress_filters.rb
+++ b/plugins/octopress_filters.rb
@@ -126,6 +126,9 @@ module OctopressLiquidFilters
input.titlecase
end
+ def downcase_escaped_url(input)
+ input.gsub(/%(\d|[ABCDEF]){2}/) { |mat| mat.downcase }
+ end
end
Liquid::Template.register_filter OctopressLiquidFilters
diff --git a/source/_includes/disqus.html b/source/_includes/disqus.html
index 33eb68b..4dc468a 100644
--- a/source/_includes/disqus.html
+++ b/source/_includes/disqus.html
@@ -5,8 +5,8 @@
{% if page.comments == true %}
{% comment %} `page.comments` can be only be set to true on pages/posts, so we embed the comments here. {% endcomment %}
// var disqus_developer = 1;
- var disqus_identifier = '{{ site.url }}{{ page.url}}';
- var disqus_url = '{{ site.url }}{{ page.url}}';
+ var disqus_identifier = '{{ site.url }}{{ page.url | downcase_escaped_url }}';
+ var disqus_url = '{{ site.url }}{{ page.url | downcase_escaped_url }}';
var disqus_script = 'embed.js';
{% else %}
{% comment %} As `page.comments` is empty, we must be on the index page. {% endcomment %}
diff --git a/source/_includes/head.html b/source/_includes/head.html
index 0fdc401..515a6ce 100644
--- a/source/_includes/head.html
+++ b/source/_includes/head.html
@@ -16,7 +16,7 @@
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
- {% capture canonical %}{{ site.url }}{% if site.permalink contains '.html' %}{{ page.url }}{% else %}{{ page.url | remove:'index.html' | strip_slash }}{% endif %}{% endcapture %}
+ {% capture canonical %}{{ site.url }}{% if site.permalink contains '.html' %}{{ page.url | downcase_escaped_url }}{% else %}{{ page.url | downcase_escaped_url | remove:'index.html' | strip_slash }}{% endif %}{% endcapture %}
<link rel="canonical" href="{{ canonical }}">
<link href="{{ root_url }}/favicon.png" rel="icon">
<link href="{{ root_url }}/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
diff --git a/source/_includes/post/sharing.html b/source/_includes/post/sharing.html
index e32500d..02c6bd6 100644
--- a/source/_includes/post/sharing.html
+++ b/source/_includes/post/sharing.html
@@ -1,6 +1,6 @@
<div class="sharing">
{% if site.twitter_tweet_button %}
- <a href="http://twitter.com/share" class="twitter-share-button" data-url="{{ site.url }}{{ page.url }}" data-via="{{ site.twitter_user }}" data-counturl="{{ site.url }}{{ page.url }}" >Tweet</a>
+ <a href="http://twitter.com/share" class="twitter-share-button" data-url="{{ site.url }}{{ page.url | downcase_escaped_url }}" data-via="{{ site.twitter_user }}" data-counturl="{{ site.url }}{{ page.url | downcase_escaped_url }}" >Tweet</a>
{% endif %}
{% if site.google_plus_one %}
<div class="g-plusone" data-size="{{ site.google_plus_one_size }}"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment