diff --git a/scripts/generate_site.py b/scripts/generate_site.py index b951e8a2d..d66bec9eb 100644 --- a/scripts/generate_site.py +++ b/scripts/generate_site.py @@ -6107,6 +6107,11 @@ def system_install_choices(coverages: dict) -> dict[str, dict[str, list[tuple[st # stays under 600 KB from 300 KB. game-engines was one 10.5 MB page that # took 21 s of main-thread work on a phone. SYSTEM_PAGE_BUDGET = 300_000 +# Manufacturers whose every console gets a page of its own, whatever its +# size. A section shares its page's search fields with its neighbours, and +# a digit is on too many pages to weigh: "playstation 3 bios" found the +# PlayStation page before the Sony page that held the PlayStation 3. +CONSOLE_PAGES = frozenset({"Sony"}) # What the sections kept on a manufacturer's summary may weigh once # rendered, estimated from their Markdown. Fitted on the Nintendo, Sega and # Commodore summaries: highlighted install commands grow about eleven times @@ -7281,7 +7286,7 @@ def system_pages( boxes = {console: _install_box_weight(install_block(console)) for console in consoles} rendered = {console: CARD_HTML_RATIO * weights[console] + INSTALL_HTML_RATIO * boxes[console] for console in weights} - if (not boards and len(measured_text) <= budget + if (not boards and manufacturer not in CONSOLE_PAGES and len(measured_text) <= budget and sum(rendered.values()) <= SYSTEM_SUMMARY_HTML): text = whole_page(all_sections()) if markup.starlight() else measured_text return {slug: (text, consoles)} @@ -7290,7 +7295,7 @@ def system_pages( # to pages of their own until what stays on the manufacturer's page is # half the budget: a section of one file keeps its place, and a reader # does not open 91 pages to browse Other. - moved: set[str] = set(boards) + moved: set[str] = set(boards) | (set(consoles) if manufacturer in CONSOLE_PAGES else set()) for console in sorted(weights, key=lambda c: (-weights[c], c)): if sum(w for c, w in weights.items() if c not in moved) <= budget // 2: break diff --git a/tests/test_site_r3_components.py b/tests/test_site_r3_components.py index d83c3a91a..704391aae 100644 --- a/tests/test_site_r3_components.py +++ b/tests/test_site_r3_components.py @@ -404,5 +404,23 @@ class SearchConsoleOwnership(unittest.TestCase): (DIST / "index.html").read_text(encoding="utf-8")) + +class EverySonyConsoleHasItsPage(unittest.TestCase): + """A section shares its page's search fields: "playstation 3 bios" + found the PlayStation page before the Sony page holding the PS3.""" + + def test_sony_is_split_by_console(self): + source = (REPO_ROOT / "scripts" / "generate_site.py").read_text(encoding="utf-8") + self.assertIn('CONSOLE_PAGES = frozenset({"Sony"})', source) + self.assertIn("manufacturer in CONSOLE_PAGES", source) + + @unittest.skipUnless((DIST / "index.html").is_file(), "site not built") + def test_each_console_page_is_built(self): + for slug in ("sony-playstation", "sony-playstation-2", "sony-playstation-3", + "sony-playstation-4", "sony-playstation-portable", "sony-playstation-vita", + "sony-pocketstation"): + with self.subTest(page=slug): + self.assertTrue((DIST / "systems" / slug / "index.html").is_file()) + if __name__ == "__main__": unittest.main() diff --git a/website/tools/search_gate.py b/website/tools/search_gate.py index 2c0d0368d..4ed41a265 100644 --- a/website/tools/search_gate.py +++ b/website/tools/search_gate.py @@ -71,11 +71,16 @@ QUERIES: dict[str, tuple[tuple[str, ...], int]] = { "game boy bios": (("systems/nintendo-game-boy/",), 1), "3ds bios": (("systems/nintendo-3ds/",), 1), # A console another one's name begins with, both ways: the longer name's - # page holds every word of the shorter query. GBA, GBC and the - # PlayStation 3 are sections of their maker's page. Saturn.emu is an - # emulator named after its console. + # page holds every word of the shorter query. GBA and GBC are sections + # of their maker's page. Saturn.emu is an emulator named after its + # console. "playstation 2 bios": (("systems/sony-playstation-2/",), 1), - "playstation 3 bios": (("systems/sony/",), 1), + # Every Sony console has a page of its own (CONSOLE_PAGES). The search + # weighs words, not their order, and "3" is on too many pages to weigh: + # the PlayStation page, which names BIOS v3.0 and leads "playstation + # bios", stays just above. "ps3 bios" finds the page first. + "playstation 3 bios": (("systems/sony-playstation-3/",), 2), + "ps3 bios": (("systems/sony-playstation-3/",), 1), "game boy advance bios": (("systems/nintendo/",), 1), "game boy color bios": (("systems/nintendo/",), 1), "nintendo ds bios": (("systems/nintendo-nintendo-ds/",), 1),