mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-23 20:29:06 -05:00
fix: link a system to the section of its name
A system link followed the folder its files sit in: emerson-arcadia-2001 reached the Saturn and sega-naomi the Dreamcast. It now goes to the section system_name() reads, or stays a plain name. Console headings carry an explicit id, so Sega's Mega-CD no longer shares mega-cd.
This commit is contained in:
1 parent
a9181f9d04
commit
bb13e7b5f9
4 files changed
+153
-27
No files matched your search
+13
-12
@@ -2355,13 +2355,13 @@ def _system_heading_link(sys_id: str, prefix: str = "") -> str:
|
||||
writes. A system with no section of its own is named, never sent to the
|
||||
page a storage folder chose.
|
||||
"""
|
||||
from siterender import _own_section
|
||||
from siterender import system_section
|
||||
|
||||
name = _escape_tags(system_name(sys_id))
|
||||
section = _own_section(sys_id)
|
||||
section = system_section(sys_id)
|
||||
if section is not None:
|
||||
mfr, console = section
|
||||
name = f"[{name}]({console_href(_slug(mfr), console, prefix)})"
|
||||
slug, console = section
|
||||
name = f"[{name}]({console_href(slug, console, prefix)})"
|
||||
return f"{name} <small>{_escape_tags(sys_id)}</small>"
|
||||
|
||||
|
||||
@@ -3436,8 +3436,7 @@ def generate_systems_index(manufacturers: dict) -> str:
|
||||
]
|
||||
for name, mfr, console, count in rows:
|
||||
cell = name.replace("|", "-")
|
||||
anchor = _slugify_anchor(console)
|
||||
href = f"{_slug(mfr)}.md" + (f"#{anchor}" if anchor else "")
|
||||
href = console_href(_slug(mfr), console).removeprefix("systems/")
|
||||
lines.append(f"| [{cell}]({href}) | {count:,} | [{mfr}]({_slug(mfr)}.md) |")
|
||||
lines.append("")
|
||||
|
||||
@@ -4291,11 +4290,12 @@ def _console_heading(manufacturer: str, console: str) -> str:
|
||||
"""A console's heading: its icon hidden from screen readers, then the
|
||||
name with no space before it. The space read as "Section titled
|
||||
“ PlayStation”" on five of seven Sony headings."""
|
||||
anchor = f" {{ #{console_anchor(manufacturer, console)} }}"
|
||||
icon = _icon_name(manufacturer, console)
|
||||
if not _icon_available.get(icon):
|
||||
return f"## {console}"
|
||||
return f"## {console}{anchor}"
|
||||
image = markup.image("", _icon_url(icon), width="24", **{"aria-hidden": "true"})
|
||||
return f"## {image}{console}"
|
||||
return f"## {image}{console}{anchor}"
|
||||
|
||||
|
||||
_NEXT_FROM_SYSTEMS = [
|
||||
@@ -4500,13 +4500,13 @@ def _named_system_link(sys_id: str, prefix: str = "") -> str:
|
||||
The emulator pages printed the id ("sony-playstation") where every
|
||||
other page says "Sony PlayStation". The id stays in the address only.
|
||||
"""
|
||||
from siterender import _page_by_norm # noqa: PLC0415
|
||||
from siterender import system_section # noqa: PLC0415
|
||||
|
||||
name = system_name(sys_id).replace("[", r"\[").replace("]", r"\]")
|
||||
page = _system_page_map.get(sys_id) or _page_by_norm(sys_id)
|
||||
if not page:
|
||||
section = system_section(sys_id)
|
||||
if not section:
|
||||
return name
|
||||
slug, console = page
|
||||
slug, console = section
|
||||
return f"[{name}]({console_href(slug, console, prefix)})"
|
||||
|
||||
|
||||
@@ -7934,6 +7934,7 @@ from siterender import ( # noqa: E402,F401
|
||||
system_name,
|
||||
card_page,
|
||||
console_href,
|
||||
console_anchor,
|
||||
record_console_pages,
|
||||
record_emulator_cards,
|
||||
emulator_card_page,
|
||||
|
||||
+61
-5
@@ -170,13 +170,31 @@ def split_system_stems() -> set[str]:
|
||||
return {stem for stems in _console_pages.values() for stem in stems}
|
||||
|
||||
|
||||
# (manufacturer slug, console) -> the id of the console's heading. Two
|
||||
# folders spelled alike (Sega's "Mega CD" and "Mega-CD") share a slug, and
|
||||
# the second heading took "mega-cd_1" while every link said "mega-cd".
|
||||
_console_anchors: dict[tuple[str, str], str] = {}
|
||||
|
||||
|
||||
def _manufacturer_slug(manufacturer: str) -> str:
|
||||
return manufacturer.lower().replace(" ", "-")
|
||||
|
||||
|
||||
def console_anchor(manufacturer: str, console: str) -> str:
|
||||
"""The id of a console's heading on its manufacturer's page."""
|
||||
from sitestarlight import toc_slug
|
||||
|
||||
key = (_manufacturer_slug(manufacturer), console)
|
||||
return _console_anchors.get(key) or toc_slug(console)
|
||||
|
||||
|
||||
def console_href(slug: str, console: str, prefix: str = "") -> str:
|
||||
"""Where a console's files are: its own page, or its section of the
|
||||
manufacturer's page (also where a console cut into parts lists them)."""
|
||||
stems = _console_pages.get((slug, console))
|
||||
if stems and len(stems) == 1:
|
||||
return f"{prefix}systems/{urllib.parse.quote(stems[0])}.md"
|
||||
return f"{prefix}systems/{urllib.parse.quote(slug)}.md#{_slugify_anchor(console)}"
|
||||
return f"{prefix}systems/{urllib.parse.quote(slug)}.md#{console_anchor(slug, console)}"
|
||||
|
||||
|
||||
def card_page(path: str, sha1: str) -> str:
|
||||
@@ -204,11 +222,33 @@ def emulator_card_page(emulator: str, anchor: str) -> str:
|
||||
return _emulator_card_pages.get((emulator, anchor), emulator)
|
||||
|
||||
|
||||
def system_section(sys_id: str) -> tuple[str, str] | None:
|
||||
"""The console section a system id is named after, as (manufacturer
|
||||
slug, console): its own section, else the one section whose heading
|
||||
reads system_name(). The folder a system's files sit in is no answer:
|
||||
Emerson's Arcadia 2001 led to the Saturn and Sega's NAOMI to the
|
||||
Dreamcast."""
|
||||
own = _own_section(sys_id)
|
||||
if own is not None:
|
||||
return _manufacturer_slug(own[0]), own[1]
|
||||
try:
|
||||
name = system_name(sys_id)
|
||||
except KeyError:
|
||||
return None
|
||||
places = _sections_by_name.get(name.casefold(), set())
|
||||
if len(places) != 1:
|
||||
return None
|
||||
mfr, console = next(iter(places))
|
||||
if mfr in _PROGRAM_TOPS:
|
||||
return None
|
||||
return _manufacturer_slug(mfr), console
|
||||
|
||||
|
||||
def _system_link(sys_id: str, prefix: str = "") -> str:
|
||||
"""Generate a markdown link to a system page with anchor."""
|
||||
page = _system_page_map.get(sys_id) or _page_by_norm(sys_id)
|
||||
if page:
|
||||
slug, console = page
|
||||
"""A system id linked to the section named after it, or the bare id."""
|
||||
section = system_section(sys_id)
|
||||
if section:
|
||||
slug, console = section
|
||||
return f"[{sys_id}]({console_href(slug, console, prefix)})"
|
||||
return sys_id
|
||||
|
||||
@@ -322,6 +362,8 @@ _PROGRAM_TOPS = frozenset({"Other", "Arcade"})
|
||||
|
||||
# Normalized id -> the console sections spelled that way.
|
||||
_console_sections: dict[str, set[tuple[str, str]]] = {}
|
||||
# A console section by the name its heading reads (Bandai WonderSwan).
|
||||
_sections_by_name: dict[str, set[tuple[str, str]]] = {}
|
||||
# Emulator and engine names. A heading spelled like one (Game Engines >
|
||||
# Solarus, ZC > ZC210) files that program's copies and names no system.
|
||||
_program_names: set[str] = set()
|
||||
@@ -355,7 +397,21 @@ def set_console_sections(
|
||||
{(mfr, console) for mfr, consoles in sections.items() for console in consoles}
|
||||
if isinstance(sections, dict) else set(sections)
|
||||
)
|
||||
from sitestarlight import _unique, toc_slug
|
||||
|
||||
_console_sections.clear()
|
||||
_sections_by_name.clear()
|
||||
_console_anchors.clear()
|
||||
by_maker: dict[str, list[str]] = {}
|
||||
for mfr, console in pairs:
|
||||
by_maker.setdefault(mfr, []).append(console)
|
||||
for name in {_heading_name(mfr, console).casefold(), console.casefold()}:
|
||||
_sections_by_name.setdefault(name, set()).add((mfr, console))
|
||||
# In the order the page lists them, after the page title's own id.
|
||||
for mfr, consoles in by_maker.items():
|
||||
used = {toc_slug(mfr)}
|
||||
for console in sorted(consoles):
|
||||
_console_anchors[(_manufacturer_slug(mfr), console)] = _unique(toc_slug(console), used)
|
||||
for mfr, console in pairs:
|
||||
spelled = console.lower().replace(" ", "-")
|
||||
slug = mfr.lower().replace(" ", "-")
|
||||
|
||||
Reference in new issue
Block a user