mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-02 16:21:32 -08:00
generate titles from microblog posts - handle invalid html
This commit is contained in:
parent
4d7acb9396
commit
970013d21b
1 changed files with 8 additions and 5 deletions
13
app/utils.py
13
app/utils.py
|
@ -245,12 +245,15 @@ def markdown_to_text(markdown_text) -> str:
|
|||
|
||||
|
||||
def microblog_content_to_title(html: str) -> str:
|
||||
soup = BeautifulSoup(html, 'html.parser')
|
||||
if '<p>' in html:
|
||||
soup = BeautifulSoup(html, 'html.parser')
|
||||
|
||||
title = ''
|
||||
for tag in soup.find_all('p'):
|
||||
title = tag.get_text()
|
||||
break
|
||||
title = ''
|
||||
for tag in soup.find_all('p'):
|
||||
title = tag.get_text()
|
||||
break
|
||||
else:
|
||||
title = shorten_string(html, 160)
|
||||
|
||||
period_index = title.find('.')
|
||||
if period_index != -1:
|
||||
|
|
Loading…
Add table
Reference in a new issue