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.
This commit is contained in:
swaits committed 2026-11-20 13:49:40 -07:00
1 parent 3997c7286e
commit 228f1cd2f7
3 files changed
+46 -3

No files matched your search

+20 -2
View File
@@ -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 <a href="/regions/#{places.KINDS[k].segment}">{PLACE_WAYS_IN[k]}</a>'
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'<p class="finder__foot finder__places">Browse {text}.</p>'
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"))}
<div class="finder__notes">
<p class="finder__foot">Not for navigation: tracks vary in quality and some trails are unfinished. Check each trail&rsquo;s own maps before you go.</p>
{places_line(place_kinds)}
{contribute}
</div>
</div>"""
+1 -1
View File
@@ -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)))
+25
View File
@@ -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'<p class="finder__foot finder__places">(.*?)</p>', 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('<li class="entry"'))
self.assertGreater(body.index("finder__places"), body.index('id="browse-list"'))
self.assertLess(body.index("</section>"), body.index("finder__places"))
def test_only_the_kinds_with_pages_and_none_when_there_are_none(self):
line = re.search(r'finder__places">(.*?)</p>', 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):