Rebuild the site for people browsing trails
The site read like a database. It is now a place to find and read about long trails, and everything on it is still derived from the records. - One kind of thing: a trail. A route is a kind of trail, explained where the word first appears. The navigation is Trails, Places, About. - The home page is the catalogue, with filters for where, length, time, season, terrain, kind, walking, shape and GPX. A filter is offered only when at least a third of the trails have a value for it. - Lists (for example National Scenic Trails and Routes) and a Places page that groups states and provinces into regions. - A trail page leads with what a hiker needs: summary, at a glance, map, downloads, elevation profile and where to go next. The dataset's own fields sit in a collapsed "About this data" section. - The trail list is a compact card on phones and beside the filters, and a column table where it has the full page width. - web/serve.py takes --bind, for viewing from another device. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
efb6164737
commit
b817d2097b
21 files changed
+3468
-719
No files matched your search
+319
-217
@@ -1,22 +1,23 @@
|
||||
"""The home page: what the site is, the overview map, and the trail finder with every record.
|
||||
"""The home page: the catalogue. Search, the filters, and the trails as a list and on a map.
|
||||
|
||||
The list of records (results(), entry()) is shared with the region pages and
|
||||
the routes page, so every list of records on the site looks and reads the same.
|
||||
The list (results(), entry()) is shared with the place pages and the lists, so
|
||||
every list of trails on the site looks and reads the same. The filters are the
|
||||
attributes in olt/facets.py, under the same names the trail pages use.
|
||||
"""
|
||||
import collections
|
||||
import math
|
||||
import re
|
||||
|
||||
from . import common, words
|
||||
from . import browse, common, elevation, facets, hike, words
|
||||
from .markup import Markup, esc
|
||||
|
||||
# Length range choices (km) for the filters. length_steps() adds a top step
|
||||
# above the longest record, so a chosen upper bound can always reach every record.
|
||||
# above the longest trail, so a chosen upper bound can always reach every trail.
|
||||
LENGTH_STEPS = (60, 80, 100, 150, 200, 300, 500, 1000, 2000, 4000, 8000)
|
||||
|
||||
|
||||
def length_steps(records):
|
||||
"""LENGTH_STEPS plus a round step at or above the longest record, when that is longer."""
|
||||
"""LENGTH_STEPS plus a round step at or above the longest trail, when that is longer."""
|
||||
longest = max((r["length_km"] for r in records), default=0)
|
||||
steps = list(LENGTH_STEPS)
|
||||
if longest > steps[-1]:
|
||||
@@ -26,27 +27,31 @@ def length_steps(records):
|
||||
|
||||
|
||||
def counts(records):
|
||||
"""Counts for the filters. A record counts under each country it touches (its own
|
||||
country and its regions' countries) and under each of its regions, as on /regions/;
|
||||
a Canada-wide record counts under "region:CA-*", not under each province."""
|
||||
"""Counts for the filter options: each Where value, Time band, month, terrain, Kind,
|
||||
Walking, Shape and GPX status, as the filter would find them."""
|
||||
c = collections.Counter()
|
||||
for r in records:
|
||||
c["total"] += 1
|
||||
c[common.kind(r)] += 1
|
||||
c["line" if common.has_line(r) else "record_only"] += 1
|
||||
if common.is_route(r):
|
||||
c["route_line" if common.has_line(r) else "route_record_only"] += 1
|
||||
c["policy:" + common.policy(r)] += 1
|
||||
c["tier:" + r.get("tier", "")] += 1
|
||||
for country in common.countries(r):
|
||||
c["country:" + country] += 1
|
||||
for key in set(words.region_key(code, r["country"]) for code in r.get("regions", [])):
|
||||
c["region:" + key] += 1
|
||||
for tok in facets.where_tokens(r):
|
||||
c["where:" + tok] += 1
|
||||
c["time:" + facets.time_band(r)] += 1
|
||||
for m in facets.months(r):
|
||||
c[f"month:{m}"] += 1
|
||||
for t in facets.terrain(r):
|
||||
c["terrain:" + t] += 1
|
||||
c["kind:" + facets.kind(r)] += 1
|
||||
if facets.walking(r):
|
||||
c["walking:" + facets.walking(r)] += 1
|
||||
if facets.shape(r):
|
||||
c["shape:" + facets.shape(r)] += 1
|
||||
c["gpx:" + facets.gpx(r)] += 1
|
||||
if facets.gpx_here(r):
|
||||
c["gpx_here"] += 1
|
||||
return c
|
||||
|
||||
|
||||
def overview_bbox(records):
|
||||
"""data-bbox attribute: the extent of every line, so the map opens on it before the data loads."""
|
||||
"""data-bbox attribute: the extent of every track, so the map opens on it before the data loads."""
|
||||
boxes = [r["derived"]["bbox"] for r in records if r["derived"].get("bbox")]
|
||||
if not boxes:
|
||||
return ""
|
||||
@@ -58,61 +63,95 @@ def sort_name(rec):
|
||||
return re.sub(r"^The ", "", rec["name"]).lower()
|
||||
|
||||
|
||||
def entry(rec, *, level=3, extra=""):
|
||||
"""One record in a list. Its data-* attributes drive the filters in app.js.
|
||||
# A row ------------------------------------------------------------------------
|
||||
|
||||
level: the heading level of the record's name. extra: HTML placed last in the row.
|
||||
def entry_desc(rec):
|
||||
"""The one-line description of a row: the [hike] summary's first sentence, else
|
||||
the trail's designation (an official trail) or nothing (a route says who made it)."""
|
||||
one = hike.one_line(rec)
|
||||
if one:
|
||||
return one
|
||||
if facets.kind(rec) == "route":
|
||||
return ""
|
||||
return rec.get("designation", "")
|
||||
|
||||
|
||||
def where_html(rec):
|
||||
"""The states and provinces of a row, each linked to its place page, and the country."""
|
||||
parts = []
|
||||
for key in facets.place_keys(rec):
|
||||
name = facets.place_name(key)
|
||||
text = esc(name) if key == facets.ACROSS_CANADA else \
|
||||
Markup(f'<abbr title="{esc(name)}">{esc(key.split("-", 1)[1])}</abbr>')
|
||||
parts.append(f'<a href="{esc(facets.place_path(key))}">{text}</a>')
|
||||
country = " and ".join(words.COUNTRIES.get(c, c) for c in common.countries(rec))
|
||||
return Markup(" ".join(parts) + f' <span aria-hidden="true">·</span> {esc(country)}')
|
||||
|
||||
|
||||
def gpx_cell(rec):
|
||||
status = facets.gpx(rec)
|
||||
route = facets.kind(rec) == "route"
|
||||
if facets.gpx_here(rec):
|
||||
swatch = common.SWATCH_ROUTE if route else common.SWATCH_LINE
|
||||
partial = (f'<p class="entry__partial">{esc(common.partial_short_text(rec))}</p>'
|
||||
if common.line_differs(rec) else "")
|
||||
return (f'<span class="line__status">{swatch}{esc(facets.GPX_SHORT[status])}</span>'
|
||||
f'<span class="line__detail">GPX and GeoJSON</span>{partial}')
|
||||
return f'<span class="line__status">{common.SWATCH_NONE}{esc(facets.GPX_SHORT[status])}</span>'
|
||||
|
||||
|
||||
def entry(rec, *, level=3, extra="", routes_list=False):
|
||||
"""One trail in a list. Its data-* attributes drive the filters in app.js.
|
||||
|
||||
level: the heading level of the trail's name. extra: HTML placed last in the row.
|
||||
routes_list: the Routes list, whose "By <author>" headings already say what the
|
||||
row's Route badge and "Route by" line would repeat; both are left out there.
|
||||
"""
|
||||
route = common.is_route(rec)
|
||||
if route:
|
||||
r = rec["route"]
|
||||
desc = "By " + r["creator"] + (f", {r['year']}" if r.get("year") else "")
|
||||
elif rec.get("tier") == "national" and common.designated_year(rec):
|
||||
desc = "Designated " + common.designated_year(rec)
|
||||
else:
|
||||
desc = rec.get("designation", "")
|
||||
where = Markup(f'{common.regions_html(rec, linked=True)} <span aria-hidden="true">·</span> '
|
||||
f'{esc(words.COUNTRIES.get(rec["country"], rec["country"]))}')
|
||||
policy = common.policy_chip(common.policy(rec)) if route else ""
|
||||
partial = common.line_differs(rec)
|
||||
if common.has_line(rec):
|
||||
partial_note = (f'<p class="entry__partial">{esc(common.partial_short_text(rec))}</p>'
|
||||
if partial else "")
|
||||
line = (f'<span class="line__status">{common.SWATCH_ROUTE if route else common.SWATCH_LINE}Track{policy}</span>'
|
||||
f'{partial_note}'
|
||||
f'<span class="line__detail">GeoJSON, GPX</span>'
|
||||
f'<span class="line__detail">{esc(common.short_source(rec))} · {esc(common.licence_label(rec))}</span>')
|
||||
note = ""
|
||||
else:
|
||||
line = f'<span class="line__status">{common.SWATCH_NONE}Record only{policy}</span>'
|
||||
note = (f'\n <p class="entry__note"><span class="vh">Why there is no track: </span>'
|
||||
f'{esc(common.absent_reason_short(rec))}</p>')
|
||||
regions = " ".join(words.region_key(c, rec["country"]) for c in rec.get("regions", []))
|
||||
search = " ".join([rec["name"], rec.get("short_name", ""), rec["id"]]
|
||||
+ ([rec["route"]["creator"]] if route else [])).lower()
|
||||
route = facets.kind(rec) == "route"
|
||||
lo, hi, est = facets.time_days(rec)
|
||||
search = " ".join([rec["name"], rec.get("short_name", ""), rec["id"], facets.author(rec)]).lower()
|
||||
abbr_cls = "entry__abbr" if common.shield_url(rec) else "entry__abbr vh"
|
||||
data = (f' data-id="{esc(rec["id"])}" data-country="{esc(rec["country"])}"'
|
||||
f' data-countries="{esc(" ".join(common.countries(rec)))}" data-regions="{esc(regions)}"'
|
||||
f' data-km="{rec["length_km"]}" data-kind="{esc(common.kind(rec))}"'
|
||||
f' data-line="{"yes" if common.has_line(rec) else "no"}"{' data-partial="yes"' if partial else ""}'
|
||||
f' data-tier="{esc(rec.get("tier", ""))}"'
|
||||
f' data-policy="{esc(common.policy(rec))}" data-name="{esc(sort_name(rec))}" data-search="{esc(search)}"')
|
||||
elev = elevation.get(rec)
|
||||
# A climb worked out from a track that covers only part of the trail, or more
|
||||
# than the trail, would mislead in a list; the trail's own page gives it with
|
||||
# its caveat.
|
||||
if elev and elevation.coverage_kind(elev):
|
||||
elev = None
|
||||
data = {
|
||||
"id": rec["id"], "where": " ".join(facets.where_tokens(rec)), "km": rec["length_km"],
|
||||
"climb": elev["ascent_m"] if elev else "",
|
||||
"days": hi, "time": facets.time_band(rec), "months": " ".join(map(str, facets.months(rec))),
|
||||
"terrain": " ".join(facets.terrain(rec)), "kind": facets.kind(rec), "walking": facets.walking(rec),
|
||||
"shape": facets.shape(rec), "gpx": facets.gpx(rec), "name": sort_name(rec), "search": search.strip(),
|
||||
}
|
||||
attrs = "".join(f' data-{k}="{esc(v)}"' for k, v in data.items())
|
||||
if common.line_differs(rec):
|
||||
attrs += ' data-partial="yes"'
|
||||
h = f"h{level}"
|
||||
return f"""<li class="entry"{data}>
|
||||
tag_html = common.badges(rec, route_tag=not routes_list)
|
||||
kicker = f'\n <p class="entry__kicker">{tag_html}</p>' if tag_html else ""
|
||||
by = f'\n <p class="entry__by">{esc(facets.route_by(rec))}</p>' if route and not routes_list else ""
|
||||
desc = entry_desc(rec)
|
||||
desc_html = f'\n <p class="entry__desc">{esc(desc)}</p>' if desc else ""
|
||||
time_html = esc(facets.time_text(rec)) + (' <small class="entry__est">estimate</small>' if est else "")
|
||||
climb_html = (f'\n <div class="entry__climb"><dt>Climb</dt><dd>{words.elevation(elev["ascent_m"], "stack")}'
|
||||
f'<small class="entry__est">computed</small></dd></div>') if elev else ""
|
||||
return f"""<li class="entry"{attrs}>
|
||||
{common.plate(rec)}
|
||||
<div class="entry__body">
|
||||
<p class="entry__kicker">{common.tags(rec, with_policy=False)}</p>
|
||||
<{h} class="entry__name"><a href="{esc(common.trail_path(rec))}">{common.name(rec)}</a> <span class="{abbr_cls}">{esc(rec.get("short_name", ""))}</span></{h}>
|
||||
<p class="entry__desc">{esc(desc)}</p>
|
||||
<p class="entry__where">{where}</p>
|
||||
<div class="entry__body">{kicker}
|
||||
<{h} class="entry__name"><a href="{esc(common.trail_path(rec))}">{common.name(rec)}</a> <span class="{abbr_cls}">{esc(rec.get("short_name", ""))}</span></{h}>{by}{desc_html}
|
||||
<p class="entry__where">{where_html(rec)}</p>
|
||||
</div>
|
||||
<dl class="entry__facts">
|
||||
<div class="entry__length"><dt>Length</dt><dd>{words.length(rec["length_km"], "stack", rec["derived"]["length_mi"])}<span class="loglen" style="--km: {rec["length_km"]}" aria-hidden="true"></span></dd></div>
|
||||
<div class="entry__line"><dt>Track</dt><dd class="line line--{"yes" if common.has_line(rec) else "no"}">{line}</dd></div>
|
||||
</dl>{note}{extra}
|
||||
<div class="entry__time"><dt>Time</dt><dd>{time_html}</dd></div>
|
||||
<div class="entry__line"><dt>GPX</dt><dd class="line line--{"yes" if facets.gpx_here(rec) else "no"}">{gpx_cell(rec)}</dd></div>{climb_html}
|
||||
</dl>{extra}
|
||||
</li>"""
|
||||
|
||||
|
||||
# The filters ------------------------------------------------------------------
|
||||
|
||||
def _length_options(steps, selected_any_last):
|
||||
opts = [f'<option value="{km}">{km:,} km · {words.fmt_int(words.km_to_mi(km))} mi</option>'
|
||||
for km in steps]
|
||||
@@ -121,97 +160,138 @@ def _length_options(steps, selected_any_last):
|
||||
return '<option value="">Any</option>' + "".join(opts[:-1])
|
||||
|
||||
|
||||
def region_options(c):
|
||||
"""The region filter: each state, province and territory a record names, with the
|
||||
count its /regions/ page shows; the Canada-wide records under their own option."""
|
||||
groups = []
|
||||
for country, table in (("US", words.US_STATES), ("CA", words.CA_PROVINCES)):
|
||||
opts = []
|
||||
if country == "CA" and c["region:CA-*"]:
|
||||
key = words.region_key(words.ALL_CANADA, "CA")
|
||||
opts.append(f'<option value="{esc(key)}">{esc(words.region_name(words.ALL_CANADA))} '
|
||||
f'({c["region:" + key]})</option>')
|
||||
for code, name in sorted(table.items(), key=lambda kv: kv[1]):
|
||||
n = c[f"region:{country}-{code}"]
|
||||
if n:
|
||||
opts.append(f'<option value="{country}-{code}">{esc(name)} ({n})</option>')
|
||||
groups.append(f'<optgroup label="{esc(words.COUNTRIES[country])}" data-country="{country}">{"".join(opts)}</optgroup>')
|
||||
return "".join(groups)
|
||||
def where_options(c):
|
||||
"""The Where filter: the two countries, then each place group with its states and provinces."""
|
||||
opts = [f'<option value="">Anywhere ({c["total"]})</option>']
|
||||
for code in ("US", "CA"):
|
||||
if c["where:" + code]:
|
||||
opts.append(f'<option value="{code}">{esc(words.COUNTRIES[code])} ({c["where:" + code]})</option>')
|
||||
for g, name, keys in facets.PLACE_GROUPS:
|
||||
if not c["where:g:" + g]:
|
||||
continue
|
||||
inner = [f'<option value="g:{g}">All of {esc(name)} ({c["where:g:" + g]})</option>']
|
||||
for key in sorted(keys, key=facets.place_name):
|
||||
if c["where:" + key]:
|
||||
inner.append(f'<option value="{key}">{esc(facets.place_name(key))} ({c["where:" + key]})</option>')
|
||||
opts.append(f'<optgroup label="{esc(name)}">{"".join(inner)}</optgroup>')
|
||||
if c["where:" + facets.ACROSS_CANADA]:
|
||||
opts.append(f'<option value="{facets.ACROSS_CANADA}">{facets.ACROSS_CANADA_NAME} '
|
||||
f'({c["where:" + facets.ACROSS_CANADA]})</option>')
|
||||
return "".join(opts)
|
||||
|
||||
|
||||
def finder_form(c, steps=LENGTH_STEPS):
|
||||
tier_opts = "".join(
|
||||
f'<option value="{t}">{esc(words.label(words.TIERS, t))} ({c["tier:" + t]})</option>'
|
||||
for t in ("national", "regional", "short", "deferred", "candidate") if c["tier:" + t])
|
||||
policy_opts = "".join(
|
||||
f'<option value="{p}">{esc(words.label(words.POLICIES, p))}: {esc(words.meaning(words.POLICIES, p).lower())} ({c["policy:" + p]})</option>'
|
||||
for p in ("open", "sold", "withheld", "unclear") if c["policy:" + p])
|
||||
def _checks(name, items, c, prefix, hints=None):
|
||||
"""Checkboxes for a multi-choice facet: (value, label) items with their counts."""
|
||||
out = []
|
||||
for value, label in items:
|
||||
n = c[f"{prefix}:{value}"]
|
||||
if not n:
|
||||
continue
|
||||
hint = f'<span class="check__hint">{esc(hints[value])}</span>' if hints and hints.get(value) else ""
|
||||
out.append(f'<label class="check"><input type="checkbox" name="{name}" value="{esc(value)}">'
|
||||
f'<span class="check__text">{esc(label)} <span class="check__count">{n}</span></span>{hint}</label>')
|
||||
return "".join(out)
|
||||
|
||||
|
||||
def _missing(records, key):
|
||||
"""The note under an optional facet: how many trails it leaves out while it is in use."""
|
||||
_, without = facets.coverage(records, key)
|
||||
if not without:
|
||||
return ""
|
||||
return (f'<p class="field__hint filter-missing" data-missing="{key}" hidden>'
|
||||
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):
|
||||
"""Search and the first-rank filters in view; Walking, Shape and GPX behind "More"."""
|
||||
c = c or counts(records)
|
||||
steps = steps or length_steps(records)
|
||||
first, more = [], []
|
||||
first.append(f"""<div class="field">
|
||||
<label class="field__label" for="where">{facets.WHERE}</label>
|
||||
<select class="select" id="where" name="where">{where_options(c)}</select>
|
||||
</div>""")
|
||||
first.append(f"""<fieldset class="field">
|
||||
<legend>{facets.LENGTH}</legend>
|
||||
<div class="range">
|
||||
<label class="vh" for="min">Shortest length</label>
|
||||
<select class="select" id="min" name="min" data-length-options>{_length_options(steps, False)}</select>
|
||||
<span class="range__to" aria-hidden="true">to</span>
|
||||
<label class="vh" for="max">Longest length</label>
|
||||
<select class="select" id="max" name="max" data-length-options>{_length_options(steps, True)}</select>
|
||||
</div>
|
||||
<p class="field__hint" id="len-hint" aria-live="polite">Any length.</p>
|
||||
</fieldset>""")
|
||||
first.append(f"""<fieldset class="field">
|
||||
<legend>{facets.TIME}</legend>
|
||||
<div class="pills">{_checks("time", [(k, label) for k, label, _ in facets.TIME_BANDS], c, "time")}</div>
|
||||
<p class="field__hint">To walk it all. Where no source says, it is estimated from the length.</p>
|
||||
</fieldset>""")
|
||||
if facets.offered(records, "season"):
|
||||
month_opts = "".join(f'<option value="{i}">{esc(m)} ({c[f"month:{i}"]})</option>'
|
||||
for i, m in enumerate(facets.MONTHS, 1))
|
||||
first.append(f"""<div class="field">
|
||||
<label class="field__label" for="month">{facets.SEASON}</label>
|
||||
<select class="select" id="month" name="month"><option value="">Any month</option>{month_opts}</select>
|
||||
<p class="field__hint">Trails usually walked in that month.</p>
|
||||
{_missing(records, "season")}
|
||||
</div>""")
|
||||
if facets.offered(records, "terrain"):
|
||||
first.append(f"""<fieldset class="field">
|
||||
<legend>{facets.TERRAIN}</legend>
|
||||
<div class="pills">{_checks("terrain", facets.TERRAIN_VALUES.items(), c, "terrain")}</div>
|
||||
{_missing(records, "terrain")}
|
||||
</fieldset>""")
|
||||
first.append(f"""<fieldset class="field">
|
||||
<legend>{facets.KIND}</legend>
|
||||
<div class="seg">
|
||||
<label><input type="radio" name="kind" value="" checked><span>Any</span></label>
|
||||
<label><input type="radio" name="kind" value="trail"><span>Official trails ({c["kind:trail"]})</span></label>
|
||||
<label><input type="radio" name="kind" value="route"><span>Routes ({c["kind:route"]})</span></label>
|
||||
</div>
|
||||
<p class="field__hint"><a href="/routes/">What is a route?</a></p>
|
||||
</fieldset>""")
|
||||
if facets.offered(records, "walking"):
|
||||
more.append(f"""<fieldset class="field">
|
||||
<legend>{facets.WALKING}</legend>
|
||||
{_checks("walking", facets.WALKING_VALUES.items(), c, "walking", facets.WALKING_HINT)}
|
||||
{_missing(records, "walking")}
|
||||
</fieldset>""")
|
||||
if facets.offered(records, "shape"):
|
||||
more.append(f"""<fieldset class="field">
|
||||
<legend>{facets.SHAPE}</legend>
|
||||
{_checks("shape", facets.SHAPES.items(), c, "shape")}
|
||||
{_missing(records, "shape")}
|
||||
</fieldset>""")
|
||||
more.append(f"""<fieldset class="field">
|
||||
<legend>{facets.GPX}</legend>
|
||||
{_checks("gpx", facets.GPX_STATUS.items(), c, "gpx")}
|
||||
</fieldset>""")
|
||||
return f"""<form class="filters" id="finder-form" role="search" aria-label="Find a trail">
|
||||
<div class="filters__search field">
|
||||
<label class="field__label" for="q">Search</label>
|
||||
<input class="input" id="q" name="q" type="search" placeholder="Name, abbreviation or creator" autocomplete="off" spellcheck="false">
|
||||
<input class="input" id="q" name="q" type="search" placeholder="Name, abbreviation or author of a route" autocomplete="off" spellcheck="false">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="check">
|
||||
<input type="checkbox" name="line">
|
||||
<span class="check__text">Has a downloadable track <span class="check__count">{c["line"]}</span></span>
|
||||
<span class="check__hint">GeoJSON and GPX. The other {c["record_only"]} are records only.</span>
|
||||
</label>
|
||||
</div>
|
||||
<details class="filters__more">
|
||||
<summary>Filters <span class="filters__active"></span></summary>
|
||||
<div class="filters__form">
|
||||
<fieldset class="field">
|
||||
<legend>Country</legend>
|
||||
<div class="seg">
|
||||
<label><input type="radio" name="country" value="all" checked><span>Both ({c["total"]})</span></label>
|
||||
<label><input type="radio" name="country" value="US"><span>United States ({c["country:US"]})</span></label>
|
||||
<label><input type="radio" name="country" value="CA"><span>Canada ({c["country:CA"]})</span></label>
|
||||
</div>
|
||||
<p class="field__hint">A record that crosses the border counts under both.</p>
|
||||
</fieldset>
|
||||
<div class="field">
|
||||
<label class="field__label" for="region">State, province or territory</label>
|
||||
<select class="select" id="region" name="region"><option value="">Any</option>{region_options(c)}</select>
|
||||
</div>
|
||||
<fieldset class="field field--wide">
|
||||
<legend>Length</legend>
|
||||
<div class="range">
|
||||
<label class="vh" for="min">Shortest length</label>
|
||||
<select class="select" id="min" name="min" data-length-options>{_length_options(steps, False)}</select>
|
||||
<span class="range__to" aria-hidden="true">to</span>
|
||||
<label class="vh" for="max">Longest length</label>
|
||||
<select class="select" id="max" name="max" data-length-options>{_length_options(steps, True)}</select>
|
||||
</div>
|
||||
<p class="field__hint" id="len-hint" aria-live="polite">Any length.</p>
|
||||
</fieldset>
|
||||
<fieldset class="field">
|
||||
<legend>Kind</legend>
|
||||
<label class="check">
|
||||
<input type="checkbox" name="designated" checked>
|
||||
<span class="check__text">Designated trails <span class="check__count">{c["designated"]}</span></span>
|
||||
<span class="check__hint">Designated by a land agency or a trail association</span>
|
||||
</label>
|
||||
<label class="check">
|
||||
<input type="checkbox" name="route" checked>
|
||||
<span class="check__text">Person-defined routes <span class="check__count">{c["route"]}</span></span>
|
||||
<span class="check__hint">Worked out and published by a person or a small group</span>
|
||||
</label>
|
||||
<label class="field__label field__label--sub" for="policy">Route track policy</label>
|
||||
<select class="select" id="policy" name="policy"><option value="">Any</option>{policy_opts}</select>
|
||||
</fieldset>
|
||||
<div class="field">
|
||||
<label class="field__label" for="tier">Tier</label>
|
||||
<select class="select" id="tier" name="tier"><option value="">Any</option>{tier_opts}</select>
|
||||
</div>
|
||||
<div class="field field--wide">
|
||||
<button class="button button--quiet" type="reset">Clear search and filters</button>
|
||||
</div>
|
||||
<details class="filters__panel" open>
|
||||
<summary>Filters <span class="filters__count"></span></summary>
|
||||
<div class="filters__first">
|
||||
{"".join(first)}
|
||||
</div>
|
||||
</details>
|
||||
<details class="filters__more">
|
||||
<summary>More filters <span class="filters__active"></span></summary>
|
||||
<div class="filters__form">
|
||||
{"".join(more)}
|
||||
</div>
|
||||
</details>
|
||||
<div class="field filters__reset">
|
||||
<button class="button button--quiet" type="reset">Clear search and filters</button>
|
||||
</div>
|
||||
</form>"""
|
||||
|
||||
|
||||
# The list ---------------------------------------------------------------------
|
||||
|
||||
# The length strip's ticks (style.css .loglen): 100, 1,000 and 10,000 km.
|
||||
SCALE_KM = (100, 1000, 10000)
|
||||
|
||||
@@ -227,8 +307,10 @@ def list_head():
|
||||
f'<span class="len__mi">{words.fmt_int(words.km_to_mi(km))}{mi_unit}</span></span>')
|
||||
return f"""<div class="list-head" aria-hidden="true">
|
||||
<span>Trail</span>
|
||||
<span>Length<span class="list-head__scale">{"".join(ticks)}</span></span>
|
||||
<span>Track</span>
|
||||
<span>{facets.LENGTH}<span class="list-head__scale">{"".join(ticks)}</span></span>
|
||||
<span>{facets.TIME}</span>
|
||||
<span>{facets.GPX}</span>
|
||||
<span>Climb</span>
|
||||
</div>"""
|
||||
|
||||
|
||||
@@ -245,35 +327,40 @@ SORT_SELECT = """<label class="results-sort">Sort
|
||||
<option value="name">Name, A to Z</option>
|
||||
<option value="long">Longest first</option>
|
||||
<option value="short">Shortest first</option>
|
||||
<option value="quick">Quickest first</option>
|
||||
<option value="climb">Most climb first</option>
|
||||
</select>
|
||||
</label>"""
|
||||
|
||||
|
||||
def key():
|
||||
def key(official=True):
|
||||
"""official: False on a list of routes only, which has no official trail to explain."""
|
||||
first = f"<li>{common.SWATCH_LINE}Official trail with a GPX here</li>\n " if official else ""
|
||||
return f"""<ul class="key" aria-label="Key to the list">
|
||||
<li>{common.SWATCH_LINE}Track in the dataset</li>
|
||||
<li>{common.SWATCH_NONE}Record only; the note says why</li>
|
||||
<li>Route track policy:
|
||||
{common.policy_chip("open")} {common.policy_chip("sold")} {common.policy_chip("withheld")} {common.policy_chip("unclear")}
|
||||
</li>
|
||||
{first}<li>{common.SWATCH_ROUTE}Route with a GPX here</li>
|
||||
<li>{common.SWATCH_NONE}No GPX here: its page says where to get one</li>
|
||||
</ul>"""
|
||||
|
||||
|
||||
def results(recs=None, *, finder=False, groups=None):
|
||||
"""The list of records, as every page shows it: div.results > head, key, list head, ol.entries.
|
||||
def results(recs=None, *, finder=False, groups=None, routes_list=False):
|
||||
"""The list of trails, as every page shows it: div.results > head, key, list head, ol.entries.
|
||||
|
||||
finder: the home page's list, driven by the finder form (live count, sort, empty state).
|
||||
groups: [(heading, records, extra_fn)] to list the records under level-3 headings
|
||||
(the routes page); extra_fn(rec) gives HTML placed last in each row.
|
||||
finder: the home page's list, driven by the filters (live count, sort, empty state).
|
||||
groups: [(heading, trails, extra_fn)] to list the trails under level-3 headings;
|
||||
extra_fn(rec) gives HTML placed last in each row.
|
||||
routes_list: passed to entry() for the Routes list (see there).
|
||||
"""
|
||||
if groups is None:
|
||||
groups = [(None, recs, None)]
|
||||
total = sum(len(g[1]) for g in groups)
|
||||
noun = "record" if total == 1 else "records"
|
||||
shown = [r for g in groups for r in g[1]]
|
||||
only_routes = bool(shown) and all(facets.kind(r) == "route" for r in shown)
|
||||
noun = ("route" if only_routes else "trail") + ("" if total == 1 else "s")
|
||||
lists = ""
|
||||
for heading, items, extra_fn in groups:
|
||||
level = 4 if heading else 3
|
||||
rows = "\n".join(entry(r, level=level, extra=extra_fn(r) if extra_fn else "") for r in items)
|
||||
rows = "\n".join(entry(r, level=level, extra=extra_fn(r) if extra_fn else "",
|
||||
routes_list=routes_list) for r in items)
|
||||
if heading:
|
||||
lists += f'\n <h3 class="results__group">{heading}</h3>'
|
||||
list_id = ' id="entries"' if finder else ""
|
||||
@@ -284,7 +371,7 @@ def results(recs=None, *, finder=False, groups=None):
|
||||
tools = SORT_SELECT + "\n " + UNITS_TOGGLE
|
||||
empty = """
|
||||
<div class="empty-state" id="empty-state" hidden>
|
||||
<p><strong>No records match these filters.</strong></p>
|
||||
<p><strong>No trails match these filters.</strong></p>
|
||||
<button class="button button--quiet" type="button" data-reset>Clear search and filters</button>
|
||||
</div>"""
|
||||
else:
|
||||
@@ -298,80 +385,95 @@ def results(recs=None, *, finder=False, groups=None):
|
||||
{tools}
|
||||
</div>
|
||||
</div>
|
||||
{key()}
|
||||
{key(official=not only_routes)}
|
||||
{list_head()}{lists}{empty}
|
||||
</div>""")
|
||||
|
||||
|
||||
# A map of a selection is drawn only when it has at least this many tracks.
|
||||
MAP_MIN = 3
|
||||
|
||||
|
||||
def overview_map(recs, label, *, wide=False, scope=""):
|
||||
"""The map of the given trails' tracks (the overview geometry, limited to their ids
|
||||
unless every trail is shown). "" when none of them has a track."""
|
||||
ids = [r["id"] for r in recs if "line" in r["derived"]["files"]]
|
||||
if not ids:
|
||||
return Markup('<p class="note">None of these trails has a GPX here, so there is no track to draw. '
|
||||
'Each trail’s page says where to get one.</p>')
|
||||
if len(ids) < MAP_MIN and scope != "all":
|
||||
names = words.join_names(f'<a href="{esc(common.trail_path(r))}">{common.name(r)}</a>'
|
||||
for r in recs if r["id"] in ids)
|
||||
return Markup(f'<p class="note">Only {names} {"has" if len(ids) == 1 else "have"} a GPX here, '
|
||||
'so no map of them all is drawn. Each trail’s page says where to get a track.</p>')
|
||||
ids_attr = "" if scope == "all" else f' data-ids="{esc(" ".join(ids))}"'
|
||||
n = len(ids)
|
||||
return Markup(f"""<figure class="mapfig{" mapfig--wide" if wide else ""}" data-map="overview" data-src="/data/overview.geojson"{ids_attr}{overview_bbox(recs)}>
|
||||
<div class="mapfig__frame">
|
||||
<span class="mapfig__corner mapfig__corner--nw" aria-hidden="true"></span>
|
||||
<div class="map" role="region" aria-label="{esc(label)}">
|
||||
<div class="map__fallback"></div>
|
||||
<div class="map__canvas"></div>
|
||||
<p class="map__status" role="status">The map needs JavaScript. The list has every trail.</p>
|
||||
</div>
|
||||
<span class="mapfig__corner mapfig__corner--se" aria-hidden="true"></span>
|
||||
</div>
|
||||
<figcaption class="mapfig__caption">
|
||||
<ul class="legend" aria-label="Legend">
|
||||
<li>{common.SWATCH_LINE}Official trail</li>
|
||||
<li>{common.SWATCH_ROUTE}Route</li>
|
||||
</ul>
|
||||
<p>{n} track{"s" if n != 1 else ""}, simplified for display. Select one for its name. Each trail’s page names its source, credit and licence. Base map: OpenFreeMap, © OpenMapTiles, data © OpenStreetMap contributors.</p>
|
||||
</figcaption>
|
||||
</figure>""")
|
||||
|
||||
|
||||
def lists_row(records):
|
||||
"""The ready-made lists, as a row of links with their counts. The terrain lists are
|
||||
on /lists/; here the Terrain filter does the same work."""
|
||||
items = "".join(
|
||||
f'<li><a href="{esc(browse.path(lst))}">{esc(lst.title)} <span class="chips__n">{len(recs)}</span></a></li>'
|
||||
for lst, recs in browse.shown(records) if not lst.key.startswith("terrain-"))
|
||||
if not items:
|
||||
return ""
|
||||
return f"""<nav class="lists-row" aria-labelledby="lists-title">
|
||||
<h2 id="lists-title" class="lists-row__title">Start from a list</h2>
|
||||
<ul class="chips">{items}<li><a href="/lists/">All lists</a></li></ul>
|
||||
</nav>"""
|
||||
|
||||
|
||||
def render(records, site):
|
||||
"""The home page body (HTML) for every record."""
|
||||
"""The home page body (HTML)."""
|
||||
c = counts(records)
|
||||
recs = sorted(records, key=sort_name)
|
||||
total = c["total"]
|
||||
lede = (f"A record for each of {total} long trails and routes, as a rule 50 miles (80 km) or more: "
|
||||
"what it is, how long it is, who publishes it, and on what terms its track may be passed on. "
|
||||
"Where the terms allow, download the track as GPX or GeoJSON.")
|
||||
lede = (f"{total} long-distance trails in the United States and Canada. Narrow them by where they are, "
|
||||
f"how long they take, when to walk them and what the country is like. "
|
||||
f"{c['gpx_here']} have a GPX to download.")
|
||||
contribute = ""
|
||||
if site.repo_url:
|
||||
contribute = (f'<p class="hero__caveat">Something wrong, or a trail missing? '
|
||||
contribute = (f'<p class="finder__foot">Something wrong, or a trail missing? '
|
||||
f'<a href="{esc(site.correction_url())}">Report a problem</a> or '
|
||||
f'<a href="{esc(site.new_trail_url)}">suggest a trail</a>; '
|
||||
f'the records are text files <a href="{esc(site.repo_url)}">anyone can fix or add to</a>.</p>')
|
||||
return f"""<section class="hero" aria-labelledby="hero-title">
|
||||
f'<a href="{esc(site.new_trail_url)}">suggest a trail</a>.</p>')
|
||||
return f"""<section class="hero hero--short" aria-labelledby="hero-title">
|
||||
<div class="container hero__inner">
|
||||
<p class="kicker">A public dataset · United States and Canada</p>
|
||||
<h1 id="hero-title">{esc(site.tagline)}</h1>
|
||||
<h1 id="hero-title">Find a long trail</h1>
|
||||
<p class="hero__lede">{lede}</p>
|
||||
<p class="hero__caveat">This is a dataset, not a navigation product. Tracks vary in quality, some trails are unfinished, and some records have no track at all; each of those says why.</p>
|
||||
{contribute}
|
||||
<p><a class="button button--primary hero__cta" href="#q">Find a trail</a></p>
|
||||
<div class="hero__counts">
|
||||
<dl class="tally">
|
||||
<div><dt>Records</dt><dd>{total}</dd></div>
|
||||
<div><dt><a href="/?kind=designated">Designated trails</a></dt><dd>{c["designated"]}</dd></div>
|
||||
<div><dt><a href="/?kind=route">Person-defined routes</a></dt><dd>{c["route"]}</dd></div>
|
||||
<div><dt>{common.SWATCH_LINE}<a href="/?line=1">With a track</a></dt><dd>{c["line"]}</dd></div>
|
||||
<div><dt>{common.SWATCH_NONE}Records only</dt><dd>{c["record_only"]}</dd></div>
|
||||
</dl>
|
||||
<div class="ratio" aria-hidden="true"><span class="ratio__line" style="--n: {c["line"]}"></span><span class="ratio__none" style="--n: {c["record_only"]}"></span></div>
|
||||
</div>
|
||||
{lists_row(records)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="section" aria-labelledby="map-title">
|
||||
<div class="container">
|
||||
<div class="section-head">
|
||||
<h2 id="map-title">Every track in the dataset</h2>
|
||||
<p>{c["line"]} tracks, simplified for display. Select a trail on the map for its name.</p>
|
||||
</div>
|
||||
<figure class="mapfig" data-map="overview" data-src="/data/overview.geojson"{overview_bbox(records)}>
|
||||
<div class="mapfig__frame">
|
||||
<span class="mapfig__corner mapfig__corner--nw" aria-hidden="true"></span>
|
||||
<div class="map" role="region" aria-label="Map of every track in the dataset">
|
||||
<div class="map__fallback"></div>
|
||||
<div class="map__canvas"></div>
|
||||
<p class="map__status" role="status">The map needs JavaScript. The list below has every record.</p>
|
||||
</div>
|
||||
<span class="mapfig__corner mapfig__corner--se" aria-hidden="true"></span>
|
||||
</div>
|
||||
<figcaption class="mapfig__caption">
|
||||
<ul class="legend" aria-label="Legend">
|
||||
<li>{common.SWATCH_LINE}Designated trail</li>
|
||||
<li>{common.SWATCH_ROUTE}Person-defined route</li>
|
||||
</ul>
|
||||
<p>Tracks are simplified to about 750 m here; each keeps the credit and licence named on its page. Base map: OpenFreeMap, © OpenMapTiles, data © OpenStreetMap contributors.</p>
|
||||
</figcaption>
|
||||
</figure>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="section" id="finder" aria-labelledby="finder-title">
|
||||
<section class="section section--finder" id="finder" aria-labelledby="finder-title">
|
||||
<div class="container finder__grid">
|
||||
<div class="finder__head section-head">
|
||||
<h2 id="finder-title">Find a trail</h2>
|
||||
<p>Search, then narrow by country, region, length, kind and track</p>
|
||||
<h2 class="vh" id="finder-title">Every trail</h2>
|
||||
{finder_form(records, c, length_steps(records))}
|
||||
<div class="finder__main">
|
||||
{overview_map(records, "Map of the trails the filters leave", wide=True, scope="all")}
|
||||
{results(recs, finder=True)}
|
||||
</div>
|
||||
<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>
|
||||
{contribute}
|
||||
</div>
|
||||
{finder_form(c, length_steps(records))}
|
||||
{results(recs, finder=True)}
|
||||
</div>
|
||||
</section>"""
|
||||
Reference in new issue
Block a user