Trim website metadata title and description (#383)

* feat: trim fetched metadata placeholders

* feat: implement trimming serverside

* Add website loader tests

* Address review comments

Co-authored-by: Sascha Ißbrücker <sascha.issbruecker@gmail.com>
This commit is contained in:
Luca
2023-01-12 21:06:36 +01:00
committed by GitHub
parent 13e0516961
commit c2d8cde86b
2 changed files with 29 additions and 2 deletions

View File

@@ -29,9 +29,9 @@ def load_website_metadata(url: str):
page_text = load_page(url)
soup = BeautifulSoup(page_text, 'html.parser')
title = soup.title.string if soup.title is not None else None
title = soup.title.string.strip() if soup.title is not None else None
description_tag = soup.find('meta', attrs={'name': 'description'})
description = description_tag['content'] if description_tag is not None else None
description = description = description_tag['content'].strip() if description_tag and description_tag['content'] else None
finally:
return WebsiteMetadata(url=url, title=title, description=description)