refactor: one owner for the get page description

getpages and handheld write the description of every download page.
The unreachable copy in descriptions parsed their rendered text.
This commit is contained in:
Abdessamad Derraz committed 2026-11-23 21:02:27 +01:00
1 parent acdce07ea5
commit cdbde88017
2 files changed
+16 -9

No files matched your search

+2 -9
View File
@@ -9,7 +9,6 @@ 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
@@ -165,15 +164,9 @@ def page_description(markdown: str, relative: Path, title: str) -> str:
def _section_description(markdown: str, relative: Path, title: str, browser: str,
lead: str) -> str | None:
"""The description of a download, system, emulator or platform page,
or None for a page of another section."""
"""The description of a system, emulator or platform page, or None for
a page of another section. A download page writes its own (getpages)."""
key = relative.as_posix()
if key.startswith(f"{releaserecord.GET_DIR}/"):
size = re.search(r"^- (.+ to download\b.*?)\.?$", markdown, re.M)
if size:
return _shorten(f"{title}: the BIOS pack of this setup, {_plain_markdown(size[1])}. "
"The address stays the same and always gives the latest ZIP.", 155)
return _shorten(_first_paragraph(lead) or title, 155)
if key.startswith("systems/") and relative.stem != "index":
return _system_description(markdown, browser)
if key.startswith("emulators/") and relative.stem != "index":
+14
View File
@@ -427,6 +427,20 @@ class GetPagesSitInYourSetup(unittest.TestCase):
getpages.generate_get_page("retroarch")
self.assertEqual(descriptions.PAGE_DATA["get/retroarch.md"], {"dateModified": "-".join(tag.groups())})
def test_every_get_page_writes_its_own_description(self):
"""getpages and handheld own the description of a download page:
page_description has no branch of its own for one."""
from sitegen import handheld
saved = dict(descriptions.PAGE_DATA)
self.addCleanup(lambda: (descriptions.PAGE_DATA.clear(), descriptions.PAGE_DATA.update(saved)))
pages = [getpages.generate_get_page("retroarch"), getpages.generate_get_index(),
handheld.group_page(REPO_ROOT)]
for page in pages:
front = page.split("\n---\n", 1)[0]
self.assertRegex(front, r"(?m)^description: \"[^\"]+\"$")
self.assertNotIn("GET_DIR", (REPO_ROOT / "scripts/sitegen/descriptions.py").read_text(encoding="utf-8"))
def test_no_page_is_left_out_of_every_tab(self):
nav = _nav()
present = _present(nav) | {"orphans/alone.md"}