aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic Hemberger <mail@frederic-hemberger.de>2011-10-21 15:00:32 +0200
committerFrederic Hemberger <mail@frederic-hemberger.de>2011-10-21 15:00:32 +0200
commita81ef5e28bc2abb846a2a3da04dd43aa7ca547a1 (patch)
tree24f0da4cda6bc0304545bf3a862affbb202de68f
parent514e84831ca2d9bce27c2a209b67fce26b5c52e8 (diff)
downloadmy_new_personal_website-a81ef5e28bc2abb846a2a3da04dd43aa7ca547a1.tar.xz
my_new_personal_website-a81ef5e28bc2abb846a2a3da04dd43aa7ca547a1.zip
Improve handling of meta description
-rw-r--r--.themes/classic/source/_includes/head.html2
-rw-r--r--plugins/octopress_filters.rb27
2 files changed, 28 insertions, 1 deletions
diff --git a/.themes/classic/source/_includes/head.html b/.themes/classic/source/_includes/head.html
index 51c5415e..0fdc4019 100644
--- a/.themes/classic/source/_includes/head.html
+++ b/.themes/classic/source/_includes/head.html
@@ -8,7 +8,7 @@
<meta name="author" content="{{ site.author }}">
{% capture description %}{% if page.description %}{{ page.description }}{% else %}{{ content | raw_content }}{% endif %}{% endcapture %}
- <meta name="description" content="{{ description | strip_newlines | strip_html | truncate:150 }}">
+ <meta name="description" content="{{ description | strip_html | condense_spaces | truncate:150 }}">
{% if page.keywords %}<meta name="keywords" content="{{ page.keywords }}">{% endif %}
<!-- http://t.co/dKP3o1e -->
diff --git a/plugins/octopress_filters.rb b/plugins/octopress_filters.rb
index 997a740a..a5bb235c 100644
--- a/plugins/octopress_filters.rb
+++ b/plugins/octopress_filters.rb
@@ -79,6 +79,33 @@ module OctopressLiquidFilters
end
end
+ # Improved version of Liquid's truncate:
+ # - Doesn't cut in the middle of a word.
+ # - Uses typographically correct ellipsis (…) insted of '...'
+ def truncate(input, length)
+ if input.length > length && input[0..(length-1)] =~ /(.+)\b.+$/im
+ $1.strip + ' &hellip;'
+ else
+ input
+ end
+ end
+
+ # Improved version of Liquid's truncatewords:
+ # - Uses typographically correct ellipsis (…) insted of '...'
+ def truncatewords(input, length)
+ truncate = input.split(' ')
+ if truncate.length > length
+ truncate[0..length-1].join(' ').strip + ' &hellip;'
+ else
+ input
+ end
+ end
+
+ # Condenses multiple spaces and tabs into a single space
+ def condense_spaces(input)
+ input.gsub(/\s{2,}/, ' ')
+ end
+
# Removes trailing forward slash from a string for easily appending url segments
def strip_slash(input)
if input =~ /(.+)\/$|^\/$/