Merge the filter bar and navigation work: keep the seasons work's result wherever both resolved the same conflict
This commit is contained in:
commit
34c6ebd1d3
10 files changed
+143
-60
No files matched your search
+1
-1
@@ -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)
|
||||
|
||||
+29
-17
@@ -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:
|
||||
@@ -340,7 +336,7 @@ def finder_form(records, c=None, steps=None, where="all", bare_if_empty=False):
|
||||
<label class="field__label" for="where">{facets.WHERE}</label>
|
||||
<select class="select" id="where" name="where">{opts}</select>
|
||||
</div>""")
|
||||
kms = [r["length_km"] for r in records]
|
||||
kms = [r["length_km"] for r in records] or [0]
|
||||
if any(min(kms) < n * words.KM_PER_MI <= max(kms) for n in steps):
|
||||
first.append(f"""<fieldset class="field" data-facet="length">
|
||||
<legend>{facets.LENGTH}</legend>
|
||||
@@ -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)}""")
|
||||
|
||||
|
||||
@@ -873,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"]
|
||||
@@ -900,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’s own maps before you go.</p>
|
||||
{places_line(place_kinds)}
|
||||
{contribute}
|
||||
</div>
|
||||
</div>"""
|
||||
+1
-1
@@ -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)))
|
||||
|
||||
@@ -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()
|
||||
|
||||
+11
-5
@@ -168,6 +168,7 @@ def regions_index_page(records, site, infos=()):
|
||||
place_infos = list(infos.values()) if isinstance(infos, dict) else list(infos or ())
|
||||
blocks = ""
|
||||
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,18 @@ 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’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>
|
||||
<span id="states-and-provinces"></span>
|
||||
<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.")
|
||||
@@ -309,7 +316,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 +439,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}
|
||||
|
||||
Reference in new issue
Block a user