refactor: join name lists through core.text

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:03:21 +01:00
1 parent 4b8e91bb6f
commit a9d8e571c1
16 files changed
+54 -56

No files matched your search

+5 -9
View File
@@ -8,6 +8,7 @@ from collections import Counter
from collections.abc import Iterable
from pathlib import Path
from core.text import series
from model import releaserecord
from sitegen import measurements as sitemeasurements
from sitegen.config import SITE_NAME
@@ -84,7 +85,7 @@ def title_noun(names: Iterable[str]) -> str:
if not distinct:
return BIOS_FILES
counts = Counter(file_kind(name) for name in distinct.values())
return said_as_list([kind for kind in ("keys", "firmware", BIOS_FILES)
return series([kind for kind in ("keys", "firmware", BIOS_FILES)
if counts[kind] * 4 >= len(distinct)])
@@ -260,7 +261,7 @@ def _files_snippet(markdown: str, key: str, title: str, intro: str) -> str:
for count in range(min(len(names), 4), 0, -1):
shown = (names if count == len(names)
else [*names[:count - 1], f"{len(names) - count + 1:,} more"])
head = f"{subject}: {said_as_list(shown)}, {need}."
head = f"{subject}: {series(shown)}, {need}."
forms += [f"{head} {tail}" for tail in tails if tail] + [head]
return next((form for form in forms if len(form) <= 155), intro)
@@ -305,7 +306,7 @@ def _system_description(markdown: str, browser: str) -> str:
consoles = [name for name in consoles if name and name not in _NOT_A_CONSOLE]
if len(consoles) > 1:
shown = consoles if len(consoles) <= 4 else consoles[:3] + [f"{len(consoles) - 3} more"]
return _shorten(f"{browser} for {said_as_list(shown)}, one card per file with its "
return _shorten(f"{browser} for {series(shown)}, one card per file with its "
"hashes and the emulators that read it.", 155)
start = re.search(r"^\*\*Start with\*\*(?P<line>.*)$(?P<list>(?:\n+- .*)*)", markdown, re.M)
if start:
@@ -317,7 +318,7 @@ def _system_description(markdown: str, browser: str) -> str:
names = list(dict.fromkeys(html.unescape(name) for name in _CARD_TITLE.findall(markdown)))
if names:
shown = names if len(names) <= 3 else names[:3] + [f"{len(names) - 3} more"]
return _shorten(f"{browser}: {said_as_list(shown)}, with their hashes and the "
return _shorten(f"{browser}: {series(shown)}, with their hashes and the "
"emulators that read them.", 155)
return _shorten(f"{browser}, one card per file with its hashes and the emulators "
"that read it.", 155)
@@ -339,8 +340,3 @@ TITLE_NOUNS: dict[str, str] = {}
# manufacturer, a run of an emulator's cards), by path relative to docs/:
# their H1 already says what they are.
PART_PAGES: set[str] = set()
def said_as_list(items: list[str]) -> str:
""""a, b and c"."""
return ", ".join(items[:-1]) + f" and {items[-1]}" if len(items) > 1 else "".join(items)