forked from github/pelican
Introduce paragraph count summary (#2761)
Co-authored-by: Justin Mayer <entroP@gmail.com>
This commit is contained in:
parent
ef501a3d89
commit
513abbfdc6
6 changed files with 80 additions and 2 deletions
|
|
@ -116,6 +116,31 @@ class TestPage(TestBase):
|
|||
page = Page(**page_kwargs)
|
||||
self.assertEqual(page.summary, "")
|
||||
|
||||
def test_summary_paragraph(self):
|
||||
# If SUMMARY_MAX_PARAGRAPHS is set, the generated summary should
|
||||
# not exceed the given paragraph count.
|
||||
page_kwargs = self._copy_page_kwargs()
|
||||
settings = get_settings()
|
||||
page_kwargs["settings"] = settings
|
||||
del page_kwargs["metadata"]["summary"]
|
||||
settings["SUMMARY_MAX_PARAGRAPHS"] = 1
|
||||
settings["SUMMARY_MAX_LENGTH"] = None
|
||||
page = Page(**page_kwargs)
|
||||
self.assertEqual(page.summary, TEST_CONTENT)
|
||||
|
||||
def test_summary_paragraph_max_length(self):
|
||||
# If both SUMMARY_MAX_PARAGRAPHS and SUMMARY_MAX_LENGTH are set,
|
||||
# the generated summary should not exceed the given paragraph count and
|
||||
# not exceed the given length.
|
||||
page_kwargs = self._copy_page_kwargs()
|
||||
settings = get_settings()
|
||||
page_kwargs["settings"] = settings
|
||||
del page_kwargs["metadata"]["summary"]
|
||||
settings["SUMMARY_MAX_PARAGRAPHS"] = 1
|
||||
settings["SUMMARY_MAX_LENGTH"] = 10
|
||||
page = Page(**page_kwargs)
|
||||
self.assertEqual(page.summary, truncate_html_words(TEST_CONTENT, 10))
|
||||
|
||||
def test_summary_end_suffix(self):
|
||||
# If a :SUMMARY_END_SUFFIX: is set, and there is no other summary,
|
||||
# generated summary should contain the specified marker at the end.
|
||||
|
|
|
|||
|
|
@ -401,6 +401,23 @@ class TestUtils(LoggedTestCase):
|
|||
self.assertEqual(utils.truncate_html_words("Ӓ text", 20), "Ӓ text")
|
||||
self.assertEqual(utils.truncate_html_words("઼ text", 20), "઼ text")
|
||||
|
||||
def test_truncate_html_paragraphs(self):
|
||||
one = "<p>one</p>"
|
||||
|
||||
self.assertEqual(utils.truncate_html_paragraphs(one, 0), "")
|
||||
self.assertEqual(utils.truncate_html_paragraphs(one, 1), one)
|
||||
self.assertEqual(utils.truncate_html_paragraphs(one, 2), one)
|
||||
|
||||
two = one + "<p>two</p>"
|
||||
self.assertEqual(utils.truncate_html_paragraphs(two, 1), one)
|
||||
self.assertEqual(utils.truncate_html_paragraphs(two, 2), two)
|
||||
|
||||
three = two + "<p>three</p>"
|
||||
self.assertEqual(utils.truncate_html_paragraphs(three, 1), one)
|
||||
self.assertEqual(utils.truncate_html_paragraphs(three, 2), two)
|
||||
self.assertEqual(utils.truncate_html_paragraphs(three, 3), three)
|
||||
self.assertEqual(utils.truncate_html_paragraphs(three, 4), three)
|
||||
|
||||
def test_process_translations(self):
|
||||
fr_articles = []
|
||||
en_articles = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue