Put a row of jump links at the very top of the Places page: States and provinces, Parks, Mountain ranges and Wilderness areas, each with its number of pages

The row shows at every screen size on one compact line that wraps on a phone, and a kind with no pages is left out. The strip of regional groups below the heading no longer repeats the three kinds.
This commit is contained in:
swaits committed 2026-11-20 13:49:40 -07:00
1 parent a806522ee1
commit 3997c7286e
3 files changed
+33 -15

No files matched your search

+6
View File
@@ -2298,6 +2298,12 @@ td .linklist a { font-weight: 400; }
.lists-row li { flex: none; }
.lists-row a { min-block-size: 2.75rem; }
}
/* The Places hub's jump row: one compact line at the very top, States and provinces and each kind of
place with its number of pages; it wraps on a phone rather than scrolling. */
.places-jump { margin-block-end: var(--space-1); }
.places-jump ul { display: flex; flex-wrap: wrap; gap: 0 var(--space-4); padding: 0; list-style: none; font: 600 0.85rem/1.3 var(--font-sans); }
.places-jump a { display: inline-flex; align-items: center; min-block-size: 2.25rem; color: var(--link); }
.places-jump__n { margin-inline-start: 0.35em; color: var(--ink-2); font-weight: 400; font-variant-numeric: tabular-nums; }
.section--finder { padding-block-start: var(--space-4); }
.pills { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.pills .check { grid-template-columns: auto auto; padding: 0.15rem var(--space-2); border: 1px solid var(--rule-strong); border-radius: 999px; }
+10 -4
View File
@@ -166,8 +166,9 @@ def regions_index_page(records, site, infos=()):
a page (olt/places.py collect); each kind that has any gets a section of its own."""
by_slug, across = collect_regions(records)
place_infos = list(infos.values()) if isinstance(infos, dict) else list(infos or ())
blocks = ""
blocks = '<span id="states-and-provinces"></span>'
jump = []
kinds = []
for g, name, keys in facets.PLACE_GROUPS:
infos = sorted((by_slug[k.lower()] for k in keys if k.lower() in by_slug), key=lambda i: i["name"])
if not infos:
@@ -200,7 +201,7 @@ def regions_index_page(records, site, infos=()):
f'<li><a href="{esc(i["path"])}">{esc(i["name"])}</a>'
f'<span class="places__n">{_plural(len(i["records"]))}</span></li>'
for i in mine)
jump.append(f'<li><a href="#{esc(kind.segment)}">{esc(kind.hub_title)}<span class="lists-row__n">{len(mine)}</span></a></li>')
kinds.append(f'<li><a href="#{esc(kind.segment)}">{esc(kind.hub_title)} <span class="places-jump__n">{len(mine)}</span></a></li>')
blocks += f"""<section class="places__group" aria-labelledby="{esc(kind.segment)}">
<h2 id="{esc(kind.segment)}">{esc(kind.hub_title)}</h2>
<ul class="places__list">{rows}</ul>
@@ -214,12 +215,17 @@ def regions_index_page(records, site, infos=()):
foot = f'\n<div class="container"><p class="places__sum">Places with no listed trail: {links}.</p></div>'
n_us = sum(1 for r in records if "US" in common.countries(r))
n_ca = sum(1 for r in records if "CA" in common.countries(r))
body = f"""<div class="page-head"><div class="container"><header class="titleblock">
# One compact row at the very top, whatever the screen: the states and provinces and each kind of
# place that has pages, each with its exact number of pages.
row = (f'<nav class="places-jump" aria-label="Jump to a kind of place"><ul>'
f'<li><a href="#states-and-provinces">States and provinces <span class="places-jump__n">{len(by_slug)}</span></a></li>'
f'{"".join(kinds)}</ul></nav>') if kinds else ""
body = f"""<div class="page-head"><div class="container">{row}<header class="titleblock">
<div class="titleblock__text"><h1>Places</h1>
<p class="page-head__lede">The {len(records)} trails by state and province, grouped into parts of the
United States ({n_us}) and Canada ({n_ca}). A trail that crosses several states is on each one&rsquo;s page.{lede_more}</p>
</div></header>
<nav class="lists-row" aria-label="Jump to a part of the country{" or a kind of place" if place_infos else ""}"><ul>{"".join(jump)}</ul></nav></div></div>
<nav class="lists-row" aria-label="Jump to a part of the country"><ul>{"".join(jump)}</ul></nav></div></div>
<div class="container section places">{blocks}</div>{foot}"""
description = (f"Where the {len(records)} long trails and routes are: {n_us} in the United States and {n_ca} in Canada, "
f"by state and province, with the number in each.")
+17 -11
View File
@@ -48,18 +48,24 @@ class HubTest(unittest.TestCase):
self.assertIn("Parks, mountain ranges and wilderness areas with three or more "
"trails have pages too.", re.sub(r"\s+", " ", body))
def test_the_shortcut_strip_links_each_kind_that_has_pages(self):
def test_a_jump_row_tops_the_hub_with_exact_counts_of_pages(self):
_, _, body = regions.regions_index_page(self.records, S, infos=self.infos)
strip = str(body)[str(body).index('<nav class="lists-row"'):]
strip = strip[:strip.index("</nav>")]
self.assertIn('<a href="#parks">Parks<span class="lists-row__n">1</span></a>', strip)
self.assertIn('<a href="#ranges">Mountain ranges<span class="lists-row__n">1</span></a>', strip)
self.assertNotIn("#wilderness", strip) # no wilderness page here: no shortcut
# the regional groups are still there, before the kinds
self.assertLess(strip.index('href="#west-coast"') if 'href="#west-coast"' in strip
else strip.index("<li>"), strip.index('href="#parks"'))
body = str(body)
by_slug, _ = regions.collect_regions(self.records)
row = body[body.index('<nav class="places-jump"'):]
row = row[:row.index("</nav>")]
self.assertLess(body.index('<nav class="places-jump"'), body.index("<h1>"))
self.assertIn(f'<a href="#states-and-provinces">States and provinces <span class="places-jump__n">{len(by_slug)}</span></a>', row)
self.assertIn('<a href="#parks">Parks <span class="places-jump__n">1</span></a>', row)
self.assertIn('<a href="#ranges">Mountain ranges <span class="places-jump__n">1</span></a>', row)
self.assertNotIn("#wilderness", row) # no wilderness page here: no link
self.assertLess(row.index("#states-and-provinces"), row.index("#parks"))
self.assertIn('id="states-and-provinces"', body)
# the kinds are in the one row, not also in the strip of regional groups
strip = body[body.index('<nav class="lists-row"'):]
self.assertNotIn("#parks", strip[:strip.index("</nav>")])
_, _, plain = regions.regions_index_page(self.records, S)
self.assertNotIn('href="#parks"', str(plain))
self.assertNotIn('class="places-jump"', str(plain))
def test_the_hub_still_lists_every_state_group_as_before(self):
_, _, plain = regions.regions_index_page(self.records, S)
@@ -67,7 +73,7 @@ class HubTest(unittest.TestCase):
stripped = re.sub(r'<section class="places__group" aria-labelledby="(?:parks|ranges|wilderness)">.*?</section>',
"", str(with_places), flags=re.S)
stripped = stripped.replace(" or a kind of place", "")
stripped = re.sub(r'<li><a href="#(?:parks|ranges|wilderness)">.*?</li>', "", stripped)
stripped = re.sub(r'<nav class="places-jump".*?</nav>\s*', "", stripped, flags=re.S)
stripped = stripped.replace(
" Parks, mountain ranges and wilderness areas with three or more trails have pages too.", "")
self.assertEqual(stripped, str(plain))