Show the search box and filters on every park, range and wilderness page, however few trails it has

The bar was written only for a set of ten trails or more (home.FILTER_MIN, added with the list
and place filters on 2026-11-17), which left the Wind River Range (7 trails), Yosemite (9) and
the Ansel Adams Wilderness (5) with neither a search box nor Filters. Place pages now always
get it, and a set that nothing can narrow gets the search box alone, with no Filters button
and no empty panel. State and province pages keep the ten-trail threshold for now.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-20 12:29:05 -07:00
1 parent 30d03b8069
commit d90fa49df5
4 files changed
+57 -10

No files matched your search

+22 -8
View File
@@ -234,7 +234,8 @@ 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()). Everything is built from the page's own trails: a facet that
# 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
# 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
@@ -315,11 +316,13 @@ def _missing(records, key):
f'{esc(facets.missing_text(without, key))} They are left out while this filter is on.</p>')
def finder_form(records, c=None, steps=None, where="all"):
def finder_form(records, c=None, steps=None, where="all", bare_if_empty=False):
"""The bar (search, Filters, Clear) and the panels: the first-rank filters, then Walking, Shape and
GPX behind "More". records: the page's own trails. where: the Where filter's scope ("all",
"g:<group>" on a group's page, "" for none: a state's page). A facet is written only when it can
narrow these trails; each field carries data-facet, for app.js to hide it when it no longer can."""
narrow these trails; each field carries data-facet, for app.js to hide it when it no longer can.
bare_if_empty: a set that nothing can narrow gets the search box alone, with no Filters
button and no empty panel."""
c = c or counts(records)
steps = steps or length_steps(records)
km_steps = length_steps(records, "km")
@@ -398,6 +401,16 @@ def finder_form(records, c=None, steps=None, where="all"):
{"".join(more)}
</div>
</details>""" if more else ""
if bare_if_empty and not first and not more:
return """<form class="filters" id="finder-form" role="search" aria-label="Find a trail">
<div class="filters__bar">
<div class="filters__search field">
<label class="vh" for="q">Search</label>
<input class="input" id="q" name="q" type="search" placeholder="Search by name, place or author" autocomplete="off" spellcheck="false">
</div>
<button class="button button--quiet filters__clear" type="reset" hidden>Clear</button>
</div>
</form>"""
return f"""<form class="filters" id="finder-form" role="search" aria-label="Find a trail">
<div class="filters__bar">
<div class="filters__search field">
@@ -420,14 +433,15 @@ def finder_form(records, c=None, steps=None, where="all"):
</form>"""
def listing(recs=None, *, where="all", groups=None, **kw):
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). where: the Where filter's scope
(finder_form). The other arguments are results()'s."""
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."""
trails = [r for g in groups for r in g[1]] if groups is not None else list(recs)
if len(trails) < FILTER_MIN:
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)}</div>
return Markup(f"""<div class="finder__bar">{finder_form(trails, where=where, bare_if_empty=always)}</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)
in_name=_in_name, phrase=_phrase, always_filters=True)
PARK = _kind()
+2 -1
View File
@@ -308,6 +308,7 @@ 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):
@@ -431,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), 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, always=kind.always_filters), 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}