mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-02 16:21:32 -08:00
improve post teasers by avoid common fail modes
This commit is contained in:
parent
f6661b7b9d
commit
91dbe4c30b
1 changed files with 9 additions and 3 deletions
12
app/utils.py
12
app/utils.py
|
@ -424,9 +424,15 @@ def microblog_content_to_title(html: str) -> str:
|
|||
|
||||
def first_paragraph(html):
|
||||
soup = BeautifulSoup(html, 'html.parser')
|
||||
first_paragraph = soup.find('p')
|
||||
if first_paragraph:
|
||||
return f'<p>{first_paragraph.text}</p>'
|
||||
first_para = soup.find('p')
|
||||
if first_para:
|
||||
if first_para.text.strip() == 'Summary' or \
|
||||
first_para.text.strip() == 'Comments' or \
|
||||
first_para.text.lower().startswith('cross-posted from: https'):
|
||||
second_paragraph = first_para.find_next('p')
|
||||
if second_paragraph:
|
||||
return f'<p>{second_paragraph.text}</p>'
|
||||
return f'<p>{first_para.text}</p>'
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue