From 0b5215c0f5530e29810deb71e2a27042c3e1284b Mon Sep 17 00:00:00 2001 From: Frederic Hemberger Date: Wed, 21 Sep 2011 10:08:38 +0200 Subject: Adds first 150 chars of content as meta description, if no page.description specified. Fixes #162 --- .themes/classic/source/_includes/head.html | 10 ++++------ plugins/octopress_filters.rb | 7 +++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.themes/classic/source/_includes/head.html b/.themes/classic/source/_includes/head.html index be371e92..5d817657 100644 --- a/.themes/classic/source/_includes/head.html +++ b/.themes/classic/source/_includes/head.html @@ -6,18 +6,16 @@ {% if page.title %}{{page.title}} - {% endif %}{{site.title}} - {% if page.description %} - - {% endif %} + + {% capture description %}{% if page.description %}{{ page.description }}{% else %}{{ content | raw_content }}{% endif %}{% endcapture %} + + {% if page.keywords %}{% endif %} - {% if page.keywords %} - - {% endif %} {% capture canonical %}{{ site.url }}{% if site.permalink contains '.html' %}{{ page.url }}{% else %}{{ page.url | remove:'index.html' }}{% endif %}{% endcapture %} diff --git a/plugins/octopress_filters.rb b/plugins/octopress_filters.rb index 1a959892..bade7e49 100644 --- a/plugins/octopress_filters.rb +++ b/plugins/octopress_filters.rb @@ -56,6 +56,13 @@ module OctopressLiquidFilters 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) + /.
(?[\s\S]*?)<\/div>\s*<\/article>/ =~ input + return (content.nil?) ? input : content + end + # Replaces relative urls with full urls def expand_urls(input, url='') url ||= '/' -- cgit v1.2.1