This commit is contained in:
Justin Mayer 2024-06-25 15:00:54 +02:00
commit 03265efb46
4 changed files with 10 additions and 10 deletions

View file

@ -162,10 +162,10 @@ author you can use ``author`` field.
If you do not explicitly specify summary metadata for a given post, the If you do not explicitly specify summary metadata for a given post, the
``SUMMARY_MAX_LENGTH`` setting can be used to specify how many words from the ``SUMMARY_MAX_LENGTH`` setting can be used to specify how many words from the
beginning of an article are used as the summary. You can also use the first N beginning of an article are used as the summary. You can also use an article's
paragraphs from the post as a summary using the ``SUMMARY_MAX_PARAGRAPHS`` first N paragraphs as its summary using the ``SUMMARY_MAX_PARAGRAPHS`` setting.
setting. If both options are in use, the specified number of paragraphs will If both settings are in use, the specified number of paragraphs will
be used but may be truncated to respect the specified max length. be used but may be truncated to respect the specified maximum length.
You can also extract any metadata from the filename through a regular You can also extract any metadata from the filename through a regular
expression to be set in the ``FILENAME_METADATA`` setting. All named groups expression to be set in the ``FILENAME_METADATA`` setting. All named groups

View file

@ -311,7 +311,7 @@ Basic settings
.. data:: SUMMARY_MAX_PARAGRAPHS = None .. data:: SUMMARY_MAX_PARAGRAPHS = None
When creating a short summary of an article, this will be the number of When creating a short summary of an article, this will be the number of
paragraphs to use as the summary. This only applies if your content paragraphs to use as the summary. This only applies if your content
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 use the whole text (up to ``SUMMARY_MAX_LENGTH``) instead of just summary to use the whole text (up to ``SUMMARY_MAX_LENGTH``) instead of just
the first N paragraphs. the first N paragraphs.

View file

@ -117,7 +117,7 @@ class TestPage(TestBase):
self.assertEqual(page.summary, "") self.assertEqual(page.summary, "")
def test_summary_paragraph(self): def test_summary_paragraph(self):
# If a :SUMMARY_MAX_PARAGRAPHS: is set, the generated summary should # If SUMMARY_MAX_PARAGRAPHS is set, the generated summary should
# not exceed the given paragraph count. # not exceed the given paragraph count.
page_kwargs = self._copy_page_kwargs() page_kwargs = self._copy_page_kwargs()
settings = get_settings() settings = get_settings()
@ -129,8 +129,8 @@ class TestPage(TestBase):
self.assertEqual(page.summary, TEST_CONTENT) self.assertEqual(page.summary, TEST_CONTENT)
def test_summary_paragraph_max_length(self): def test_summary_paragraph_max_length(self):
# If a :SUMMARY_MAX_PARAGRAPHS: and :SUMMARY_MAX_LENGTH: are set, the # If both SUMMARY_MAX_PARAGRAPHS and SUMMARY_MAX_LENGTH are set,
# generated summary should not exceed the given paragraph count and # the generated summary should not exceed the given paragraph count and
# not exceed the given length. # not exceed the given length.
page_kwargs = self._copy_page_kwargs() page_kwargs = self._copy_page_kwargs()
settings = get_settings() settings = get_settings()

View file

@ -632,7 +632,7 @@ def truncate_html_words(s: str, num: int, end_text: str = "…") -> str:
def truncate_html_paragraphs(s, count): def truncate_html_paragraphs(s, count):
"""Truncates HTML to a certain number of paragraphs. """Truncate HTML to a certain number of paragraphs.
:param count: number of paragraphs to keep :param count: number of paragraphs to keep
@ -641,7 +641,7 @@ def truncate_html_paragraphs(s, count):
paragraphs = [] paragraphs = []
tag_stop = 0 tag_stop = 0
substr = s[:] substr = s[:]
for i in range(count): for _ in range(count):
substr = substr[tag_stop:] substr = substr[tag_stop:]
tag_start = substr.find("<p>") tag_start = substr.find("<p>")
tag_stop = substr.find("</p>") + len("</p>") tag_stop = substr.find("</p>") + len("</p>")