Adds first 150 chars of content as meta description, if no page.description specified. Fixes #162

This commit is contained in:
Frederic Hemberger 2011-09-21 10:08:38 +02:00
parent 48a93a90a4
commit 0b5215c0f5
2 changed files with 11 additions and 6 deletions

View File

@ -6,18 +6,16 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>{% if page.title %}{{page.title}} - {% endif %}{{site.title}}</title> <title>{% if page.title %}{{page.title}} - {% endif %}{{site.title}}</title>
<meta name="author" content="{{site.author}}"> <meta name="author" content="{{site.author}}">
{% if page.description %}
<meta name="description" content="{{page.description}}"/> {% capture description %}{% if page.description %}{{ page.description }}{% else %}{{ content | raw_content }}{% endif %}{% endcapture %}
{% endif %} <meta name="description" content="{{ description | strip_newlines | strip_html | truncate:150 }}">
{% if page.keywords %}<meta name="keywords" content="{{ page.keywords }}">{% endif %}
<!-- http://t.co/dKP3o1e --> <!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True"> <meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320"> <meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
{% if page.keywords %}
<meta name="keywords" content="{{page.keywords}}"/>
{% endif %}
{% capture canonical %}{{ site.url }}{% if site.permalink contains '.html' %}{{ page.url }}{% else %}{{ page.url | remove:'index.html' }}{% endif %}{% endcapture %} {% capture canonical %}{{ site.url }}{% if site.permalink contains '.html' %}{{ page.url }}{% else %}{{ page.url | remove:'index.html' }}{% endif %}{% endcapture %}
<link rel="canonical" href="{{ canonical }}"> <link rel="canonical" href="{{ canonical }}">
<link href="{{ root_url }}/favicon.png" rel="shortcut icon" /> <link href="{{ root_url }}/favicon.png" rel="shortcut icon" />

View File

@ -56,6 +56,13 @@ module OctopressLiquidFilters
end end
end end
# Extracts raw content DIV from template, used for page description as {{ content }}
# contains complete sub-template code on main page level
def raw_content(input)
/.<div class="entry-content">(?<content>[\s\S]*?)<\/div>\s*<\/article>/ =~ input
return (content.nil?) ? input : content
end
# Replaces relative urls with full urls # Replaces relative urls with full urls
def expand_urls(input, url='') def expand_urls(input, url='')
url ||= '/' url ||= '/'