mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
generate titles from microblog posts - sentences can end with a ?
This commit is contained in:
parent
07957513a3
commit
f111b50041
1 changed files with 8 additions and 2 deletions
10
app/utils.py
10
app/utils.py
|
@ -256,8 +256,14 @@ def microblog_content_to_title(html: str) -> str:
|
|||
title = shorten_string(html, 160)
|
||||
|
||||
period_index = title.find('.')
|
||||
if period_index != -1:
|
||||
title = title[:period_index]
|
||||
question_index = title.find('?')
|
||||
|
||||
# Find the earliest occurrence of either '.' or '?'
|
||||
end_index = min(period_index if period_index != -1 else float('inf'),
|
||||
question_index if question_index != -1 else float('inf'))
|
||||
|
||||
if end_index != -1:
|
||||
title = title[:end_index]
|
||||
|
||||
if len(title) > 150:
|
||||
for i in range(149, -1, -1):
|
||||
|
|
Loading…
Add table
Reference in a new issue