mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #2711 from galaxy4public/summary-end-marker
Add custom summary end marker
This commit is contained in:
commit
0fabbb6a60
4 changed files with 22 additions and 1 deletions
|
|
@ -271,6 +271,11 @@ Basic settings
|
||||||
does not otherwise specify a summary. Setting to ``None`` will cause the
|
does not otherwise specify a summary. Setting to ``None`` will cause the
|
||||||
summary to be a copy of the original content.
|
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
|
.. data:: WITH_FUTURE_DATES = True
|
||||||
|
|
||||||
If disabled, content with dates in the future will get a default status of
|
If disabled, content with dates in the future will get a default status of
|
||||||
|
|
|
||||||
|
|
@ -390,7 +390,8 @@ class Content(object):
|
||||||
return self.content
|
return self.content
|
||||||
|
|
||||||
return truncate_html_words(self.content,
|
return truncate_html_words(self.content,
|
||||||
self.settings['SUMMARY_MAX_LENGTH'])
|
self.settings['SUMMARY_MAX_LENGTH'],
|
||||||
|
self.settings['SUMMARY_END_MARKER'])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def summary(self):
|
def summary(self):
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,7 @@ DEFAULT_CONFIG = {
|
||||||
'ARTICLE_PERMALINK_STRUCTURE': '',
|
'ARTICLE_PERMALINK_STRUCTURE': '',
|
||||||
'TYPOGRIFY': False,
|
'TYPOGRIFY': False,
|
||||||
'TYPOGRIFY_IGNORE_TAGS': [],
|
'TYPOGRIFY_IGNORE_TAGS': [],
|
||||||
|
'SUMMARY_END_MARKER': '…',
|
||||||
'SUMMARY_MAX_LENGTH': 50,
|
'SUMMARY_MAX_LENGTH': 50,
|
||||||
'PLUGIN_PATHS': [],
|
'PLUGIN_PATHS': [],
|
||||||
'PLUGINS': None,
|
'PLUGINS': None,
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,20 @@ class TestPage(LoggedTestCase):
|
||||||
page = Page(**page_kwargs)
|
page = Page(**page_kwargs)
|
||||||
self.assertEqual(page.summary, '')
|
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):
|
def test_summary_get_summary_warning(self):
|
||||||
"""calling ._get_summary() should issue a warning"""
|
"""calling ._get_summary() should issue a warning"""
|
||||||
page_kwargs = self._copy_page_kwargs()
|
page_kwargs = self._copy_page_kwargs()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue