mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-03 00:31:25 -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)
|
title = shorten_string(html, 160)
|
||||||
|
|
||||||
period_index = title.find('.')
|
period_index = title.find('.')
|
||||||
if period_index != -1:
|
question_index = title.find('?')
|
||||||
title = title[:period_index]
|
|
||||||
|
# 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:
|
if len(title) > 150:
|
||||||
for i in range(149, -1, -1):
|
for i in range(149, -1, -1):
|
||||||
|
|
Loading…
Add table
Reference in a new issue