From 12d51fa8a01444e0a85494a66dd8162dc7327fb9 Mon Sep 17 00:00:00 2001 From: Kale Franz Date: Wed, 25 Dec 2013 15:35:32 -0600 Subject: [PATCH] Add custom configuration for summary ending text --- docs/settings.rst | 5 +++++ pelican/contents.py | 3 ++- pelican/settings.py | 1 + pelican/utils.py | 6 ++---- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/settings.rst b/docs/settings.rst index 61ee7cc3..0e7b295f 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -146,6 +146,11 @@ Setting name (default value) What doe This only applies if your content does not otherwise specify a summary. Setting to ``None`` will cause the summary to be a copy of the original content. +`SUMMARY_END_TEXT` (``' ...'``) When creating a short summary of an article, this will + be the final displayed text string of the summary. + This only applies if your content does not otherwise + specify a summary and ``SUMMARY_MAX_LENGTH`` is not set + to ``None``. `EXTRA_TEMPLATES_PATHS` (``[]``) A list of paths you want Jinja2 to search for templates. Can be used to separate templates from the theme. Example: projects, resume, profile ... diff --git a/pelican/contents.py b/pelican/contents.py index 51ef8a22..a8685427 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -270,7 +270,8 @@ class Content(object): return self.content return truncate_html_words(self.content, - self.settings['SUMMARY_MAX_LENGTH']) + self.settings['SUMMARY_MAX_LENGTH'], + self.settings['SUMMARY_END_TEXT']) def _set_summary(self, summary): """Dummy function""" diff --git a/pelican/settings.py b/pelican/settings.py index 99828935..aeb3f912 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -105,6 +105,7 @@ DEFAULT_CONFIG = { 'ARTICLE_PERMALINK_STRUCTURE': '', 'TYPOGRIFY': False, 'SUMMARY_MAX_LENGTH': 50, + 'SUMMARY_END_TEXT': ' ...', 'PLUGIN_PATH': '', 'PLUGINS': [], 'PYGMENTS_RST_OPTIONS': {}, diff --git a/pelican/utils.py b/pelican/utils.py index 4b25ec7f..71b356bf 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -360,7 +360,7 @@ def path_to_url(path): return '/'.join(split_all(path)) -def truncate_html_words(s, num, end_text='...'): +def truncate_html_words(s, num, end_text=' ...'): """Truncates HTML to a certain number of words. (not counting tags and comments). Closes opened tags if they were correctly @@ -420,9 +420,7 @@ def truncate_html_words(s, num, end_text='...'): if words <= length: # Don't try to close tags if we don't need to truncate return s - out = s[:end_text_pos] - if end_text: - out += ' ' + end_text + out = s[:end_text_pos] + end_text # Close any tags still open for tag in open_tags: out += '' % tag