@@ -345,17 +345,21 @@ def get_date_from_meta(
345
345
346
346
return out_date
347
347
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 :
349
351
"""Returns description from page meta. If it doesn't exist, use the \
350
352
{chars_count} first characters from page content (in markdown).
351
353
352
354
:param Page in_page: page to look at
353
355
:param int chars_count: if page.meta.description is not set, number of chars \
354
356
of the content to use. Defaults to: 160 - optional
357
+ :param str abstract_delimiter: description delimeter, defaults to None
355
358
356
359
:return: page description to use
357
360
:rtype: str
358
361
"""
362
+
359
363
description = in_page .meta .get ("description" )
360
364
361
365
# 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) ->
374
378
"because an item must have a description."
375
379
)
376
380
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
+ )
377
389
# 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 :
379
391
if chars_count is None or len (in_page .content ) < chars_count :
380
392
return in_page .content [:chars_count ]
381
393
# Use markdown
0 commit comments