nws: truncate NWSheadline at word boundary, no ellipsis

Cut at last space before 80 UTF-8 bytes instead of hard-slicing at 77
chars with trailing dots.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matt Johnson (via Claude) 2026-06-08 07:07:07 +00:00
commit ddf24e10a9

View file

@ -319,8 +319,9 @@ def _render(*, event_type, area_desc, geocoder_city, county, state,
nws_hl = (params.get("NWSheadline") or [""])[0].strip()
if nws_hl:
nws_hl = nws_hl.title()
if len(nws_hl) > 80:
nws_hl = nws_hl[:77] + "..."
if len(nws_hl.encode("utf-8")) > 80:
while len(nws_hl.encode("utf-8")) > 80:
nws_hl = nws_hl.rsplit(" ", 1)[0]
line2 = nws_hl
else:
area_first = (area_desc or "").split(";")[0].strip()