Skip to content

Commit d37d46f

Browse files
committed
Add abstract_delimiter logic
1 parent faa075b commit d37d46f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

mkdocs_rss_plugin/util.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,17 +345,21 @@ def get_date_from_meta(
345345

346346
return out_date
347347

348-
def get_description_or_abstract(self, in_page: Page, chars_count: int = 160) -> str:
348+
def get_description_or_abstract(
349+
self, in_page: Page, chars_count: int = 160, abstract_delimiter: str = None
350+
) -> str:
349351
"""Returns description from page meta. If it doesn't exist, use the \
350352
{chars_count} first characters from page content (in markdown).
351353
352354
:param Page in_page: page to look at
353355
:param int chars_count: if page.meta.description is not set, number of chars \
354356
of the content to use. Defaults to: 160 - optional
357+
:param str abstract_delimiter: description delimeter, defaults to None
355358
356359
:return: page description to use
357360
:rtype: str
358361
"""
362+
359363
description = in_page.meta.get("description")
360364

361365
# Set chars_count to None if it is set to be unlimited, for slicing.
@@ -374,8 +378,16 @@ def get_description_or_abstract(self, in_page: Page, chars_count: int = 160) ->
374378
"because an item must have a description."
375379
)
376380
return ""
381+
elif abstract_delimiter:
382+
if (
383+
excerpt_separator_position := in_page.markdown.find(abstract_delimiter)
384+
) > -1:
385+
return markdown.markdown(
386+
in_page.markdown[:excerpt_separator_position],
387+
output_format="html5",
388+
)
377389
# If chars count is unlimited, use the html content
378-
elif in_page.content and chars_count is None:
390+
elif in_page.content and chars_count == -1:
379391
if chars_count is None or len(in_page.content) < chars_count:
380392
return in_page.content[:chars_count]
381393
# Use markdown

0 commit comments

Comments
 (0)