From e412657581c060a117f178d1224a4bce53bbae26 Mon Sep 17 00:00:00 2001 From: "(GalaxyMaster)" Date: Sat, 11 Apr 2020 15:35:26 +1000 Subject: [PATCH 1/4] Added support for the summary end marker configuration --- pelican/contents.py | 3 ++- pelican/settings.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pelican/contents.py b/pelican/contents.py index 594cd3b5..620fa304 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -390,7 +390,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_MARKER']) @property def summary(self): diff --git a/pelican/settings.py b/pelican/settings.py index 0cdcefc7..7d80ba90 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -136,6 +136,7 @@ DEFAULT_CONFIG = { 'ARTICLE_PERMALINK_STRUCTURE': '', 'TYPOGRIFY': False, 'TYPOGRIFY_IGNORE_TAGS': [], + 'SUMMARY_END_MARKER': '…', 'SUMMARY_MAX_LENGTH': 50, 'PLUGIN_PATHS': [], 'PLUGINS': None, From 4833a272436775aa44ac197e93ef4b4de3129372 Mon Sep 17 00:00:00 2001 From: "(GalaxyMaster)" Date: Sat, 11 Apr 2020 15:42:18 +1000 Subject: [PATCH 2/4] Provided the settings documentation snippet --- docs/settings.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/settings.rst b/docs/settings.rst index b4ec4761..8ad149b2 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -271,6 +271,11 @@ Basic settings does not otherwise specify a summary. Setting to ``None`` will cause the summary to be a copy of the original content. +.. data:: SUMMARY_END_MARKER = '…' + + When creating a short summary of an article and the result was truncated to + match the required word length, this will be used as the truncation marker. + .. data:: WITH_FUTURE_DATES = True If disabled, content with dates in the future will get a default status of From 56c2abe61351f520581fc70ccc8b3c4aecd38f6d Mon Sep 17 00:00:00 2001 From: "(GalaxyMaster)" Date: Sat, 11 Apr 2020 17:30:50 +1000 Subject: [PATCH 3/4] Added a test for the emd marker --- pelican/tests/test_contents.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pelican/tests/test_contents.py b/pelican/tests/test_contents.py index 62608b7b..0ac69f8d 100644 --- a/pelican/tests/test_contents.py +++ b/pelican/tests/test_contents.py @@ -98,6 +98,19 @@ class TestPage(LoggedTestCase): page = Page(**page_kwargs) self.assertEqual(page.summary, '') + def test_summary_end_marker(self): + # If a :SUMMARY_END_MARKER: is set, and there is no other summary, + # generated summary should contain the specified marker at the end. + page_kwargs = self._copy_page_kwargs() + settings = get_settings() + page_kwargs['settings'] = settings + del page_kwargs['metadata']['summary'] + settings['SUMMARY_END_MARKER'] = 'test_marker' + settings['SUMMARY_MAX_LENGTH'] = 10 + page = Page(**page_kwargs) + self.assertEqual(page.summary, truncate_html_words(TEST_CONTENT, 10, + 'test_marker')) + def test_summary_get_summary_warning(self): """calling ._get_summary() should issue a warning""" page_kwargs = self._copy_page_kwargs() From 7f8726929ba4aa9cdf1276fe7c8394e03d0df9ba Mon Sep 17 00:00:00 2001 From: "(GalaxyMaster)" Date: Sun, 12 Apr 2020 05:18:29 +1000 Subject: [PATCH 4/4] Added an additional assert as requested --- pelican/tests/test_contents.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pelican/tests/test_contents.py b/pelican/tests/test_contents.py index 0ac69f8d..08d4eb73 100644 --- a/pelican/tests/test_contents.py +++ b/pelican/tests/test_contents.py @@ -110,6 +110,7 @@ class TestPage(LoggedTestCase): page = Page(**page_kwargs) self.assertEqual(page.summary, truncate_html_words(TEST_CONTENT, 10, 'test_marker')) + self.assertIn('test_marker', page.summary) def test_summary_get_summary_warning(self): """calling ._get_summary() should issue a warning"""