Skip to content

Commit

Permalink
Improve social media preview
Browse files Browse the repository at this point in the history
  • Loading branch information
svenseeberg committed Oct 31, 2024
1 parent c582537 commit 83348ce
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions integreat_cms/api/v3/social_media_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@

def get_excerpt(content: str) -> str:
"""
Correctly escapes, truncates and normalizes the content of the page to display in a search result
Correctly escapes, truncates and normalizes the content of the page to display in a search result.
Then apply some crazy string operations to handle several edge cases.
:param content: The content of the page
:return: A page excerpt containing the first 100 characters of "raw" content
"""
return unescape(strip_tags(content))[:100].replace("\n", " ").replace("\r", "")
stripped_content = unescape(
strip_tags(content.replace("\n", " ").replace("\r", "").replace("<br>", " "))
)
if len(stripped_content) <= 100:
return stripped_content.strip().replace(" ", " ")
return stripped_content[:100].strip().rsplit(' ', 1)[0]+" ..."


def get_region_title(region: Region, page_title: str) -> str:
Expand Down

0 comments on commit 83348ce

Please sign in to comment.