Let a place carry its own label and preposition, keep the count in every place title, and test that slugs follow names

A registry entry may now set label and prep. A plateau reads "Plateau" and "on the Colorado
Plateau", the Mogollon Rim "Escarpment" and "along the Mogollon Rim", a national monument or a
parkway its own word; the default is still "Mountain range" and "in the". Every national park,
provincial park, monument, recreation area and parkway in the registry is labelled.

A place title no longer gives up its ": N Trails" ending when it is long: it drops the state first
and then keeps the count over the cap, and the state is left out where the name already holds
it (Oregon Cascades, California Coast Ranges). A test checks that every slug is the slug of its
display name, with the Arizona White Mountains as the one stated exception.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-20 12:28:03 -07:00
1 parent a97ea85093
commit 30d03b8069
10 files changed
+307 -43

No files matched your search

+18 -17
View File
@@ -19,19 +19,15 @@ def _in_name(info):
return places.in_name(info)
def _title_place(info):
"""The name in a page's title: _in_name with its one state spelled out for a
range or wilderness area (places.title_name), "the Wind River Range, Wyoming"."""
text = places.title_name(info)
if info["kind"] in ("range", "wilderness") and not text.lower().startswith("the "):
return f"the {text}"
return text
def _phrase(info):
""""in the Wind River Range", "on the Colorado Plateau", "along the Mogollon Rim"."""
return places.in_phrase(info)
def _kicker(info):
noun = places.KINDS[info["kind"]].noun
label = info.get("label") or places.label_of(info)
names = places.state_names(info)
return f"{noun} · {words.join_names(names)}" if names else noun
return f"{label} · {words.join_names(names)}" if names else label
def _crumbs(info):
@@ -39,12 +35,17 @@ def _crumbs(info):
def _lede(info, recs, n_gpx):
return f"{regions._plural(len(recs))} in {esc(_in_name(info))}, {n_gpx} with a GPX here."
return f"{regions._plural(len(recs))} {esc(_phrase(info))}, {n_gpx} with a GPX here."
def _title_options(info, recs, site):
base = f"Long Hikes in {_title_place(info)}"
return [f"{base}: {regions._plural(len(recs), 'Trail')}", base]
"""Every title keeps the count of trails. The state goes first when the title is too long
(and is never there when the name already holds it); a title that is still over the cap
keeps its count rather than lose it. "Long Hikes" and the preposition are never cut."""
count = regions._plural(len(recs), "Trail")
prep = places.prep_of(info)
return [f"Long Hikes {prep} {info['title_name']}: {count}",
f"Long Hikes {prep} {info['name']}: {count}"]
def _description(info, recs):
@@ -58,15 +59,15 @@ def _description(info, recs):
if n_gpx else "")
by_length = sorted(recs, key=lambda r: (r["length_km"], r["id"]))
# No state keys: a trail that runs on out of the place is never sized as the place's.
first = (f"{what} in {_title_place(info)}, from {common.plain_name(by_length[0])}, "
first = (f"{what} {places.prep_of(info)} {info['title_name']}, from {common.plain_name(by_length[0])}, "
f"{regions.trail_miles(by_length[0], ())}, to {common.plain_name(by_length[-1])}, "
f"{regions.trail_miles(by_length[-1], ())}.")
return regions._fit([first + gpx, first, f"{what} in {_title_place(info)}.{gpx}"])
return regions._fit([first + gpx, first, f"{what} {places.prep_of(info)} {info['title_name']}.{gpx}"])
def _nav(info, records, recs, facet_pages):
return (regions._lists_nav(_in_name(info), recs, records)
+ regions._facet_nav(_in_name(info), facet_pages))
return (regions._lists_nav(_in_name(info), recs, records, _phrase(info))
+ regions._facet_nav(_in_name(info), facet_pages, _phrase(info)))
def _kind():
@@ -74,7 +75,7 @@ def _kind():
kicker=_kicker, crumbs=_crumbs, lede=_lede, where="all", wholly=False,
facts_place=lambda info: (_in_name(info), ()), title_options=_title_options,
description=_description, box=lambda info: info.get("box"), nav=_nav,
in_name=_in_name)
in_name=_in_name, phrase=_phrase)
PARK = _kind()
+34 -9
View File
@@ -99,24 +99,48 @@ def state_names(info):
return [words.region_name(_state_key(c).split("-", 1)[-1]) for c in info.get("where") or []]
DEFAULT_PREP = {"park": "in", "range": "in the", "wilderness": "in the"}
def label_of(entry_or_info):
"""The page's kind word, from the registry's `label` or else the kind's own."""
return entry_or_info.get("label") or KINDS[entry_or_info["kind"]].noun
def prep_of(entry_or_info):
"""The preposition a title or lede uses, from the registry's `prep` or else the kind's own:
"in the" for a range or a wilderness area, "in" for a park; "on the Colorado Plateau",
"along the Mogollon Rim" where the registry says so."""
return entry_or_info.get("prep") or DEFAULT_PREP[entry_or_info["kind"]]
def in_name(info):
"""The name as it reads after "in": a range or a wilderness area takes "the"
("in the Wind River Range"), a park does not ("in Yosemite National Park")."""
"""The name as it reads after a verb or "through" ("the Wind River Range"): with "the"
when the place's preposition has one, as the plain name where it has not."""
name = info["name"]
if info.get("kind") in ("range", "wilderness") and not name.lower().startswith("the "):
if prep_of(info).endswith(" the") and not name.lower().startswith("the "):
return f"the {name}"
return name
def in_phrase(info):
"""The preposition and the name, as a title or a lede has it: "in the Wind River Range",
"on the Colorado Plateau", "along the Mogollon Rim", "in Yosemite National Park"."""
return f"{prep_of(info)} {info['name']}"
def title_name(info):
"""The place as a page title names it: a park by its name alone; a range or a
wilderness area in one state or province with that state spelled out
("Wind River Range, Wyoming"), and with no state when it spans several."""
"""The place as a page title names it: a park by its name alone; a range or a wilderness
area in one state or province with that state spelled out ("Wind River Range, Wyoming"),
with no state when it spans several or when the name already holds it ("Oregon Cascades",
"California Coast Ranges")."""
name = info["name"]
if info.get("kind") == "park":
return name
names = state_names(info)
return f"{name}, {names[0]}" if len(names) == 1 else name
if len(names) == 1 and names[0].lower() not in name.lower():
return f"{name}, {names[0]}"
return name
_NAME_ENDS = (" national park", " provincial park", " wilderness area", " park", " wilderness")
@@ -162,8 +186,8 @@ def _same_stem(park_name, range_name):
def collect(records, registry):
"""(kind, slug) -> info for every place with a page: PAGE_MIN or more trails.
An info holds kind, slug, key ("<kind>/<slug>"), name, where, box, records, path
and title_name. A wilderness area or a mountain range that holds exactly the
An info holds kind, slug, key ("<kind>/<slug>"), name, label, prep, where, box,
records, path and title_name. A wilderness area or a mountain range that holds exactly the
trails of a park of much the same name gets no page: one page for the one set, under
the park. The registry normally already leaves such a place out; the builder stays safe."""
mem = membership(records, registry)
@@ -173,6 +197,7 @@ def collect(records, registry):
continue
e = registry[(kind, slug)]
info = {"kind": kind, "slug": slug, "key": f"{kind}/{slug}", "name": e.get("name", slug),
"label": label_of(e), "prep": prep_of(e),
"where": list(e.get("where") or []), "box": e.get("box"), "records": recs,
"path": path(kind, slug)}
info["title_name"] = title_name(info)
+18 -11
View File
@@ -292,8 +292,10 @@ class PageKind:
title_options(info, recs, site) -> titles, fullest first, for common.fit_title.
description(info, recs) -> str. box(info) -> [west, south, east, north] or None.
nav(info, records, recs, facet_pages) -> HTML after the rows and map.
in_name(info) -> str, where present: the name as it reads after "in" ("the Wind
River Range"); the plain name where the kind leaves it out."""
in_name(info) -> str, where present: the name as it reads after a verb ("the Wind
River Range"); the plain name where the kind leaves it out. phrase(info) -> str,
where present: the preposition and the name ("on the Colorado Plateau"); where the
kind leaves it out, "in" and in_name."""
kicker: object
crumbs: object
lede: object
@@ -305,6 +307,7 @@ class PageKind:
box: object
nav: object
in_name: object = None
phrase: object = None
def _state_kicker(info):
@@ -360,21 +363,24 @@ def _state_description(info, recs):
return _fit([first + gpx, first, f"{what[:1].upper() + what[1:]} in {name}, {country}.{gpx}"])
def _lists_nav(name, recs, records):
"""The nav of ready-made lists holding some of these trails, shared by the kinds."""
def _lists_nav(name, recs, records, phrase=None):
"""The nav of ready-made lists holding some of these trails, shared by the kinds.
phrase is "in <name>" unless the place has its own preposition."""
held = lists_here(recs, records)
if not held:
return ""
return (f'<nav class="region-nav" aria-label="Lists with trails in {esc(name)}">'
f'Lists with trails in {esc(name)}, and how many here: {" · ".join(held)}</nav>')
phrase = phrase or f"in {name}"
return (f'<nav class="region-nav" aria-label="Lists with trails {esc(phrase)}">'
f'Lists with trails {esc(phrase)}, and how many here: {" · ".join(held)}</nav>')
def _facet_nav(name, facet_pages):
def _facet_nav(name, facet_pages, phrase=None):
"""The nav of this place's pages of one kind of trail, shared by the kinds."""
if not facet_pages:
return ""
return (f'<nav class="region-nav" aria-label="Kinds of trail in {esc(name)}">'
f'More in {esc(name)}: '
phrase = phrase or f"in {name}"
return (f'<nav class="region-nav" aria-label="Kinds of trail {esc(phrase)}">'
f'More {esc(phrase)}: '
+ " · ".join(f'<a href="{esc(path)}">{esc(label)}</a> ({n})' for label, path, n in facet_pages)
+ "</nav>")
@@ -415,6 +421,7 @@ def place_page(info, records, site, kind, *, facet_pages=(), place_links=""):
place = kind.facts_place(info)
wholly = wholly_in(recs, place[1]) if kind.wholly else None
in_name = kind.in_name(info) if kind.in_name else info["name"]
phrase = kind.phrase(info) if kind.phrase else f"in {in_name}"
body = f"""<div class="page-head"><div class="container">
<nav class="breadcrumb" aria-label="Breadcrumb"><ol>{crumbs}<li aria-current="page">{esc(info["name"])}</li></ol></nav>
<header class="titleblock"><div class="titleblock__text">
@@ -424,9 +431,9 @@ def place_page(info, records, site, kind, *, facet_pages=(), place_links=""):
</div></header>
</div></div>
<div class="container section place">
{home.browse_view(home.listing(recs, top=2, where=kind.where, wholly=wholly), home.overview_map(recs, f"Map of the trails in {in_name}", place=kind.box(info)),
{home.browse_view(home.listing(recs, top=2, where=kind.where, wholly=wholly), home.overview_map(recs, f"Map of the trails {phrase}", place=kind.box(info)),
about=f"{summary.facts(recs, records, place=place)}{summary.details(recs)}",
about_title=f"About the trails in {in_name}")}
about_title=f"About the trails {phrase}")}
{nav}{place_links}
</div>"""
title = common.fit_title(kind.title_options(info, recs, site), site)
+66 -1
View File
@@ -39,7 +39,8 @@ def write_registry(root, entries=REGISTRY):
box = ", ".join(str(v) for v in e["box"])
where = ", ".join(f'"{c}"' for c in e["where"])
within = f'\nwithin = [{", ".join(chr(34) + s + chr(34) for s in e["within"])}]' if e.get("within") else ""
lines.append(f'[[place]]\nslug = "{e["slug"]}"\nkind = "{e["kind"]}"\nname = "{e["name"]}"\n'
extra = "".join(f'{k} = "{e[k]}"\n' for k in ("label", "prep") if e.get(k))
lines.append(f'[[place]]\nslug = "{e["slug"]}"\nkind = "{e["kind"]}"\nname = "{e["name"]}"\n{extra}'
f'where = [{where}]{within}\nsource = "{e["source"]}"\nsource_id = "{e["source_id"]}"\n'
f'source_version = "{e["source_version"]}"\nbox = [{box}]\n')
with open(os.path.join(root, "places.toml"), "w", encoding="utf-8") as f:
@@ -85,6 +86,70 @@ def text(fragment):
return re.sub(r"\s+", " ", html.unescape(re.sub(r"<[^>]+>", " ", str(fragment))))
def entry_of(kind, slug, name, where, **kw):
return dict({"kind": kind, "slug": slug, "name": name, "where": where, "source": "gmba-v2",
"source_id": "1", "source_version": "2026-11-20", "box": BOX}, **kw)
def built_with(entries, n=3, regs=("WY",)):
records = [rec(300 + i, f"Place Trail {chr(64 + i)}", [(e["kind"], e["slug"]) for e in entries],
regs=regs) for i in range(1, n + 1)]
with tempfile.TemporaryDirectory() as d:
write_registry(d, entries)
return {b.path: b for b in placepages.build(records, S, d)}
class LabelPrepositionAndTitleTest(unittest.TestCase):
def test_a_plateau_is_not_a_mountain_range_and_is_on_not_in(self):
built = built_with([entry_of("range", "colorado-plateau", "Colorado Plateau", ["UT"],
label="Plateau", prep="on the")], regs=("UT",))
b = built["/ranges/colorado-plateau/"]
body = str(b.body)
self.assertEqual(b.title, "Long Hikes on the Colorado Plateau, Utah: 3 Trails")
self.assertIn('<p class="kicker">Plateau · Utah</p>', body)
self.assertNotIn("Mountain range", body)
self.assertIn("3 trails on the Colorado Plateau", text(body))
self.assertIn("on the Colorado Plateau", b.description)
self.assertNotIn("in the Colorado Plateau", body)
def test_the_rim_is_along_and_a_range_with_no_label_keeps_the_defaults(self):
built = built_with([entry_of("range", "mogollon-rim", "Mogollon Rim", ["AZ"],
label="Escarpment", prep="along the"),
entry_of("range", "wind-river-range", "Wind River Range", ["WY"])],
regs=("AZ", "WY"))
self.assertIn("3 trails along the Mogollon Rim", text(built["/ranges/mogollon-rim/"].body))
wind = built["/ranges/wind-river-range/"]
self.assertIn('<p class="kicker">Mountain range · Wyoming</p>', str(wind.body))
self.assertIn("3 trails in the Wind River Range", text(wind.body))
def test_a_park_has_its_own_label_and_no_the(self):
built = built_with([entry_of("park", "blue-ridge-parkway", "Blue Ridge Parkway", ["NC", "VA"],
label="Parkway", prep="along the")], regs=("NC",))
b = built["/parks/blue-ridge-parkway/"]
self.assertIn('<p class="kicker">Parkway · North Carolina and Virginia</p>', str(b.body))
self.assertEqual(b.title, "Long Hikes along the Blue Ridge Parkway: 3 Trails")
def test_a_state_already_in_the_name_is_not_repeated(self):
built = built_with([entry_of("range", "oregon-cascades", "Oregon Cascades", ["OR"]),
entry_of("range", "california-coast-ranges", "California Coast Ranges", ["CA"])],
regs=("OR", "CA"))
self.assertEqual(built["/ranges/oregon-cascades/"].title, "Long Hikes in the Oregon Cascades: 3 Trails")
self.assertEqual(built["/ranges/california-coast-ranges/"].title,
"Long Hikes in the California Coast Ranges: 3 Trails")
def test_every_place_title_keeps_its_count_even_with_a_long_name(self):
built = built_with([entry_of("range", "vancouver-island-ranges", "Vancouver Island Ranges", ["BC"]),
entry_of("park", "sequoia", "Sequoia and Kings Canyon National Parks", ["CA"]),
entry_of("wilderness", "sk", "Sequoia-Kings Canyon Wilderness", ["CA"])],
n=18, regs=("BC", "CA"))
for b in built.values():
self.assertTrue(b.title.endswith(": 18 Trails"), b.title)
self.assertTrue(b.title.startswith("Long Hikes in "), b.title)
# the state goes first, then nothing else: no "Long Hikes in" is shortened
self.assertEqual(built["/ranges/vancouver-island-ranges/"].title,
"Long Hikes in the Vancouver Island Ranges: 18 Trails")
class PlacePageTest(unittest.TestCase):
@classmethod
def setUpClass(cls):