summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Mayer <entroP@gmail.com>2020-04-12 06:55:45 +0200
committerGitHub <noreply@github.com>2020-04-12 06:55:45 +0200
commit0fabbb6a60e37c1d21696f478b84b02c312c5379 (patch)
treeb0f717c105724a43071a5171e7daaedca5541aca
parente06934a003e0514e35ea2b4914157d733c3554ed (diff)
parent7f8726929ba4aa9cdf1276fe7c8394e03d0df9ba (diff)
downloadpelican-0fabbb6a60e37c1d21696f478b84b02c312c5379.tar.gz
Merge pull request #2711 from galaxy4public/summary-end-marker
Add custom summary end marker
-rw-r--r--docs/settings.rst5
-rw-r--r--pelican/contents.py3
-rw-r--r--pelican/settings.py1
-rw-r--r--pelican/tests/test_contents.py14
4 files changed, 22 insertions, 1 deletions
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
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,
diff --git a/pelican/tests/test_contents.py b/pelican/tests/test_contents.py
index 62608b7b..08d4eb73 100644
--- a/pelican/tests/test_contents.py
+++ b/pelican/tests/test_contents.py
@@ -98,6 +98,20 @@ 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'))
+ self.assertIn('test_marker', page.summary)
+
def test_summary_get_summary_warning(self):
"""calling ._get_summary() should issue a warning"""
page_kwargs = self._copy_page_kwargs()