From 228f1cd2f74980e3c787257326263df38eb9e718 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Fri, 20 Nov 2026 13:49:40 -0700 Subject: [PATCH] End the home page with a line to the pages for parks, mountain ranges and wilderness areas "Browse by park, by mountain range or by wilderness area" sits with the notes under the rows and the map, so the first screen and the rows are as they were, and each link goes to its section of the Places page. --- web/olt/home.py | 22 ++++++++++++++++++++-- web/olt/pages.py | 2 +- web/tests/test_place_links.py | 25 +++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/web/olt/home.py b/web/olt/home.py index 37235f4..876a298 100644 --- a/web/olt/home.py +++ b/web/olt/home.py @@ -867,8 +867,25 @@ def description(records): return common.cut_at_word(text, common.DESCRIPTION_LIMIT) -def render(records, site, repo_root=""): - """The home page body (HTML). repo_root: where collections.toml names the lists the page shows.""" +# How the home page's line names each kind of place, and where on the Places hub it goes. +PLACE_WAYS_IN = {"park": "park", "range": "mountain range", "wilderness": "wilderness area"} + + +def places_line(place_kinds): + """The line below the rows that leads to the Places hub's sections: "Browse by park, by mountain + range or by wilderness area." for the kinds that have pages (place_kinds: kind keys), else "".""" + from . import places # imported here: places.py is the registry, and loads datafiles like this module + links = [f'by {PLACE_WAYS_IN[k]}' + for k in places.KINDS if k in place_kinds] + if not links: + return "" + text = links[0] if len(links) == 1 else ", ".join(links[:-1]) + " or " + links[-1] + return f'

Browse {text}.

' + + +def render(records, site, repo_root="", place_kinds=()): + """The home page body (HTML). repo_root: where collections.toml names the lists the page shows. + place_kinds: the kinds of place (olt/places.py) that have pages; the page then ends with a line to them.""" c = counts(records) recs = sorted(records, key=sort_name) total = c["total"] @@ -894,6 +911,7 @@ def render(records, site, repo_root=""): {browse_view(listing, overview_map(records, "Map of the trails the filters leave", scope="all"))}

Not for navigation: tracks vary in quality and some trails are unfinished. Check each trail’s own maps before you go.

+ {places_line(place_kinds)} {contribute}
""" diff --git a/web/olt/pages.py b/web/olt/pages.py index dbd4241..45abd0f 100644 --- a/web/olt/pages.py +++ b/web/olt/pages.py @@ -125,7 +125,7 @@ def render_site(records, out_dir, repo_root, site=None): image=card, image_alt=card_alt)) dates[path] = seo.modified(rec) pages += 1 - body = home.render(records, site, repo_root) + body = home.render(records, site, repo_root, place_kinds={i["kind"] for i in place_infos.values()}) layout.write_page(out_dir, "/", layout.layout("", body, path="/", maps=True, site=site, description=home.description(records), jsonld=seo.home_jsonld(site))) diff --git a/web/tests/test_place_links.py b/web/tests/test_place_links.py index 7cf065a..b322603 100644 --- a/web/tests/test_place_links.py +++ b/web/tests/test_place_links.py @@ -29,6 +29,31 @@ def infos(records): return places.collect(records, registry()) +class HomeWayInTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.records = wind_records(4) + yosemite_records(3) + + def test_below_the_rows_a_line_links_each_kind_that_has_pages(self): + body = str(home.render(self.records, S, ROOT, place_kinds=["park", "range", "wilderness"])) + line = re.search(r'

(.*?)

', body, re.S).group(1) + self.assertEqual( + re.sub(r"<[^>]+>", "", line), + "Browse by park, by mountain range or by wilderness area.") + for frag in ('href="/regions/#parks">park', 'href="/regions/#ranges">mountain range', + 'href="/regions/#wilderness">wilderness area'): + self.assertIn(frag, line) + # after the rows and the map, in the notes at the foot, never in the intro + self.assertGreater(body.index("finder__places"), body.rindex('
  • "), body.index("finder__places")) + + def test_only_the_kinds_with_pages_and_none_when_there_are_none(self): + line = re.search(r'finder__places">(.*?)

    ', str(home.render(self.records, S, ROOT, place_kinds=["range"])), re.S).group(1) + self.assertEqual(re.sub(r"<[^>]+>", "", line), "Browse by mountain range.") + self.assertNotIn("finder__places", str(home.render(self.records, S, ROOT))) + + class HubTest(unittest.TestCase): @classmethod def setUpClass(cls):