From ff2426c4ad9e24c52d9a1d02f9c841d4a6438d00 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 13 Mar 2012 17:10:20 +0100 Subject: [PATCH] Fix for #245: return the summary of an article based on the :summary: metadata if it is set, else troncate the content. --- pelican/contents.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pelican/contents.py b/pelican/contents.py index 4f424461..d8ccf9f3 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -89,9 +89,9 @@ class Page(object): if hasattr(self, 'date') and self.date > datetime.now(): self.status = 'draft' - # set summary - if not hasattr(self, 'summary'): - self.summary = truncate_html_words(self.content, 50) + # store the :summary: metadata if it is set + if 'summary' in metadata: + self._summary = metadata['summary'] def check_properties(self): """test that each mandatory property is set.""" @@ -126,8 +126,12 @@ class Page(object): return content def _get_summary(self): - """Returns the summary of an article, based on to the content""" - return truncate_html_words(self.content, 50) + """Returns the summary of an article, based on the :summary: metadata + if it is set, else troncate the content.""" + if hasattr(self, '_summary'): + return self._summary + else: + return truncate_html_words(self.content, 50) def _set_summary(self, summary): """Dummy function"""