Skip to content

Commit 67d5595

Browse files
tiosgzGuts
authored andcommitted
[PATCH v2 1/3] fix retrieving article description
1 parent 68f7677 commit 67d5595

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

mkdocs_rss_plugin/util.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ def get_description_or_abstract(
455455
self, in_page: Page, chars_count: int = 160, abstract_delimiter: str = None
456456
) -> str:
457457
"""Returns description from page meta. If it doesn't exist, use the \
458-
{chars_count} first characters from page content (in markdown).
458+
page content up to {abstract_delimiter} or the {chars_count} first \
459+
characters from page content (in markdown).
459460
460461
:param Page in_page: page to look at
461462
:param int chars_count: if page.meta.description is not set, number of chars \
@@ -468,20 +469,16 @@ def get_description_or_abstract(
468469

469470
description = in_page.meta.get("description")
470471

471-
# Set chars_count to None if it is set to be unlimited, for slicing.
472-
if chars_count < 0:
473-
chars_count = None
474-
475472
# If the full page is wanted (unlimited chars count)
476-
if chars_count is None and (in_page.content or in_page.markdown):
473+
if chars_count == -1 and (in_page.content or in_page.markdown):
477474
if in_page.content:
478475
return in_page.content
479476
else:
480477
return markdown.markdown(in_page.markdown, output_format="html5")
481478
# If the description is explicitly given
482479
elif description:
483480
return description
484-
# If the description is cut by the delimiter
481+
# If the abstract is cut by the delimiter
485482
elif (
486483
abstract_delimiter
487484
and (
@@ -502,7 +499,7 @@ def get_description_or_abstract(
502499
f"{in_page.markdown[: chars_count - 3]}...",
503500
output_format="html5",
504501
)
505-
# No explicit description and no content is found
502+
# No explicit description and no (or empty) abstract found
506503
else:
507504
logger.warning(
508505
f"No description set for page {in_page.file.src_uri} "

0 commit comments

Comments
 (0)