Give every page that lists trails the search box and the filters that have something to offer, however few trails it holds

The cutoff of ten trails is gone, so 48 of the 60 state and province pages, the small lists and each route author's page now have the bar. A set that nothing can narrow gets the search box alone, and an option no trail has is not written. In the state-pages golden file only the hashes of the ten pages that differ changed, each by the added bar and nothing else.
This commit is contained in:
swaits committed 2026-11-20 13:48:07 -07:00
1 parent fd2e6fc6c7
commit a806522ee1
6 files changed
+53 -41

No files matched your search

+1 -1
View File
@@ -312,7 +312,7 @@ def author_page(g, records, site, all_pages):
+ " · ".join(f'<a href="{esc(path(x))}">{esc(x["name"])}</a> ({len(x["routes"])})' for x in nav_items) + "</nav>") if nav_items else ""
more = str(summary.facts(routes, records, by_authors=False)) if n >= 3 else ""
briefs = "".join(f'<h3><a href="{esc(common.trail_path(r))}">{esc(common.plain_name(r))}</a></h3>\n{trail.brief(r)}\n' for r in routes)
listing = home.results(groups=[(None, routes, regions.route_guides)], routes_list=True, top=2,
listing = home.listing(groups=[(None, routes, regions.route_guides)], routes_list=True, top=2,
by=lambda r: with_html(g, r, by_name))
route_title = "About the route" if n == 1 else "About each route"
bio = about_html(g)
+8 -14
View File
@@ -239,17 +239,13 @@ def entry(rec, *, level=3, extra="", routes_list=False, hidden=False, eager=Fals
# The filters ------------------------------------------------------------------
# One bar and one set of panels, on the home page and on every other page that shows a set of at
# least FILTER_MIN trails (listing()), and on every park, range and wilderness page whatever its
# size (the owner's rule: every set of trails gets the bar). Everything is built from the page's own trails: a facet that
# One bar and one set of panels, on the home page and on every other page that shows a set of
# trails (listing()), whatever its size (the owner's rule: every set of trails gets the bar). Everything is built from the page's own trails: a facet that
# cannot narrow them is left out, and an option none of them has is not written. The numbers written
# here are for the whole set; app.js counts again from the rows on the page every time anything
# changes, and hides an option that would show nothing (its counting is facetCounts(), which
# web/tests/test_filter_counts.py runs under node against counts made here from the records).
FILTER_MIN = 10
def _length_options(steps, selected_any_last, unit="mi"):
opts = [f'<option value="{step_value(n, unit)}">{step_label(n, unit)}</option>' for n in steps]
if selected_any_last:
@@ -443,15 +439,13 @@ def finder_form(records, c=None, steps=None, where="all", bare_if_empty=False):
</form>"""
def listing(recs=None, *, where="all", groups=None, always=False, **kw):
"""The rows of a page that shows a set of trails, with the filter bar over them when the set
has at least FILTER_MIN trails (else results() alone); with always, whatever its size (the
bar then holds only the filters that have something to offer). where: the Where filter's
scope (finder_form). The other arguments are results()'s."""
def listing(recs=None, *, where="all", groups=None, **kw):
"""The rows of a page that shows a set of trails, with the filter bar over them whatever the size
of the set (the bar holds only the filters that have something to offer, and the search box
alone where nothing can narrow the set). where: the Where filter's scope (finder_form). The
other arguments are results()'s."""
trails = [r for g in groups for r in g[1]] if groups is not None else list(recs)
if len(trails) < FILTER_MIN and not always:
return results(recs, groups=groups, **kw)
return Markup(f"""<div class="finder__bar">{finder_form(trails, where=where, bare_if_empty=always)}</div>
return Markup(f"""<div class="finder__bar">{finder_form(trails, where=where, bare_if_empty=True)}</div>
{results(recs, groups=groups, finder=True, **kw)}""")
+1 -1
View File
@@ -75,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, phrase=_phrase, always_filters=True)
in_name=_in_name, phrase=_phrase)
PARK = _kind()
+1 -2
View File
@@ -309,7 +309,6 @@ class PageKind:
nav: object
in_name: object = None
phrase: object = None
always_filters: bool = False # the filter bar whatever the number of trails
def _state_kicker(info):
@@ -433,7 +432,7 @@ 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, always=kind.always_filters), home.overview_map(recs, f"Map of the trails {phrase}", 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 {phrase}")}
{nav}{place_links}
+10 -10
View File
@@ -1,14 +1,14 @@
{
"/regions/": "e70a9608ef0ee6a97d0591ad582abff1b165371dee5111e3277df06a53a554e1",
"/regions/atlantic-canada/": "6af5c4a79cac82eb0a4342297fd4f6755890e98597a98f219087c56432f06243",
"/regions/ca-on/": "12b5726d800090233f082a572cf1472f152552cef8fa5019f49b83e32e337eef",
"/regions/central-canada/": "fa6f8bbe466b5978f1edda22371b6aab8546efa567eee0d0405c717e278b8a3e",
"/regions/mountain-west/": "c079eb93a55c2279f24083983230057940eb032cb034057c822c52230ce22e05",
"/regions/north/": "fdfd201ae1e42b8fd17dd055815d4b06392a8ddb6ac3e72a06f15ec2b333fb56",
"/regions/us-co/": "45cb1b92fd22ffc35f82a26fe2c71b66836b0624bf0e195f9c4926dfab6a8900",
"/regions/us-co/loops/": "8883c9aac63f100196f9e853d6738a42b8199f1250c10ec34d1d0cfe8c998e7d",
"/regions/us-co/with-gpx/": "abc3f7e44cbcbf8d6cce3b5d5065e6e7c085ec5a4033842af8909077f87e1e18",
"/regions/atlantic-canada/": "5146b4b9d1940a268cfd2345f1eee2263fd6c7e2dfd28adfdffc3fff0e698c93",
"/regions/ca-on/": "d4e543c6f163ba188a34444b42c494a3dbbd26c02f2b141339bbc230cd91f84e",
"/regions/central-canada/": "d7478ad682d715705770d35cc902c80c40d27719e7f9f5a1d99ec702d3f7a43e",
"/regions/mountain-west/": "6151f5a28d366fb48aab7027f08cea6da425201d0e7327780a01dd77cedc7bc7",
"/regions/north/": "85ba3ea850c2df690e311cf09257f2548ed888c07c319a01fd30d5e19cdf1fd4",
"/regions/us-co/": "97daaf3511578896b222570cba630da2d8ca0571504ce43b3685dbe532e40f56",
"/regions/us-co/loops/": "03896834b5369655f7b5f26634b6d23c834b17f1a25b0ec328d44934e20e2dfa",
"/regions/us-co/with-gpx/": "d82eace3d70eb9b1ef1346f5a3470199bd6a00e6e104fe661bfeb80199af96b8",
"/regions/us-hi/": "1e5681ffbd50e382db7d69528fde602069006bf0cddad494d817369224bd96ad",
"/regions/us-ut/": "065bcc01e14eb588dc1b118c466f44474fca0172c30037fb193d83a044624100",
"/regions/western-canada/": "91b40d35dd3d1a093d38d01bbfcf1ef536221a69631fc58e46732da81d0582c3"
"/regions/us-ut/": "906db4153def35fa5418d0b86dba908fd27396bbc2098978ee169516e1b39785",
"/regions/western-canada/": "1b102ed9d47283869fdf8c8d54229d245f2113fd53c7e8ec2ecc118fd4da3b64"
}
+32 -13
View File
@@ -1,7 +1,7 @@
"""The filter bar on every page that shows a set of trails, and the numbers beside its choices.
The bar (olt/home.py listing(), finder_form()) is the home page's, on each list, place and the Routes
page whose set has at least home.FILTER_MIN trails, built from that page's own trails. app.js counts
page, whatever the number of trails, built from that page's own trails. app.js counts
the choices again from the rows on the page every time anything changes (FacetCount, between the
facet-counts markers); this file runs that counting under node, on the rows the home page writes,
and checks it against counts made here straight from the records. Pages are rendered one at a time;
@@ -68,22 +68,36 @@ class WhichPagesHaveTheBarTest(unittest.TestCase):
lst = browse.by_key(key)
return regions.list_page(lst, self.shown[key], len(self.records), SITE, records=self.records)[2]
def test_a_list_page_a_place_page_a_part_of_the_country_and_routes_have_it(self):
self.assertGreaterEqual(len(self.shown["loops"]), home.FILTER_MIN)
self.assertTrue(form_of(self.list_body("loops")))
def test_a_list_page_a_place_page_a_part_of_the_country_and_routes_have_it(self):
self.assertTrue(form_of(self.list_body("loops")))
by_slug, _ = regions.collect_regions(self.records)
self.assertGreaterEqual(len(by_slug["ca-on"]["records"]), home.FILTER_MIN)
self.assertTrue(form_of(regions.region_page("ca-on", self.records, SITE)[2]))
self.assertTrue(form_of(regions.group_page("central-canada", self.records, SITE)[2]))
self.assertTrue(form_of(regions.routes_page(self.records, SITE)[2]))
def test_a_set_under_the_threshold_has_the_plain_rows(self):
small = [k for k, recs in self.shown.items() if len(recs) < home.FILTER_MIN and k != "routes"]
self.assertTrue(small)
def test_every_state_province_and_list_page_has_the_bar_however_few_trails(self):
by_slug, _ = regions.collect_regions(self.records)
small = [k for k, v in by_slug.items() if len(v["records"]) < 10]
self.assertGreater(len(small), 40)
for key in small:
body = self.list_body(key)
self.assertFalse(form_of(body), key)
self.assertNotIn("data-finder", str(body), key)
body = regions.region_page(key, self.records, SITE)[2]
self.assertIn('id="finder-form"', str(body), key)
self.assertIn("data-finder", str(body), key)
small_lists = [k for k, recs in self.shown.items() if len(recs) < 10 and k != "routes"]
self.assertTrue(small_lists)
for key in small_lists:
self.assertTrue(form_of(self.list_body(key)), key)
def test_a_two_trail_page_offers_only_filters_that_narrow_it(self):
by_slug, _ = regions.collect_regions(self.records)
two = [k for k, v in by_slug.items() if len(v["records"]) == 2]
self.assertTrue(two)
for key in two:
form = form_of(regions.region_page(key, self.records, SITE)[2])
self.assertIn('name="q"', form, key)
for sel in re.findall(r"<select[^>]*>(.*?)</select>", form, re.S):
self.assertNotIn("<select></select>", sel)
self.assertGreater(len(re.findall(r"<option", sel)), 1, key)
def test_the_tables_rankings_newest_authors_and_left_out_pages_do_not(self):
bodies = {}
@@ -102,14 +116,19 @@ class WhichPagesHaveTheBarTest(unittest.TestCase):
from olt import authors
groups = authors.author_pages(self.records, ROOT)
bodies["authors"] = authors.index_page(self.records, SITE, ROOT)[2]
big = max(groups, key=lambda g: len(g["routes"]))
bodies["author"] = authors.author_page(big, self.records, SITE, groups)[2]
bodies["left-out"] = leftout.left_out_page(leftout.load_entries(ROOT), SITE, ROOT)[2]
self.assertGreater(len(bodies), 4)
for name, body in bodies.items():
self.assertNotIn('id="finder-form"', str(body), name)
self.assertNotIn("data-finder", str(body), name)
def test_an_authors_own_page_has_the_bar_however_few_routes(self):
from olt import authors
groups = authors.author_pages(self.records, ROOT)
for g in (min(groups, key=lambda g: len(g["routes"])), max(groups, key=lambda g: len(g["routes"]))):
body = authors.author_page(g, self.records, SITE, groups)[2]
self.assertIn('id="finder-form"', str(body), g["name"])
def test_the_saved_page_has_no_bar(self):
from olt import saved
self.assertNotIn('id="finder-form"', str(saved.saved_page(self.records, SITE)[2]))