Add saved trails, and move the units and theme switches to the header
A visitor can save trails with a star on every list row and a Save button on each trail page. The list is kept in localStorage (lh-saved) and shown at /saved/, with a map of only those trails and a link that carries the list in its address (/saved/?t=id,id) so it can be bookmarked or sent to another device or person. A list opened from a link never overwrites the visitor's own; "Save these" adds to it. The page is noindex and left out of the sitemap. The miles/km switch and the auto/light/dark choice move from the footer to the header on every page, beside a Saved link that shows the count. They are hidden without JavaScript. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
ad2223f427
commit
46dc81523c
14 files changed
+1122
-59
No files matched your search
@@ -207,6 +207,25 @@ FOOTER_MAP_CREDIT = Markup(
|
||||
"the U.S. Geological Survey, NOAA, ArcticDEM and INEGI; Canada terrain data under the Open Government "
|
||||
"Licence - Canada. The full credit is under each trail map.")
|
||||
|
||||
def save_button(rec, *, row=True):
|
||||
"""The control that saves a trail to the visitor's saved trails, or takes it off.
|
||||
|
||||
A real <button>, never inside a link, named for the trail ("Save Pacific
|
||||
Crest Trail") whatever its state; app.js sets aria-pressed (and the word
|
||||
"Save" or "Saved" on a trail page) from the saved list, lh-saved in
|
||||
localStorage. row: the star alone, placed under the logo of a list row
|
||||
(style.css .save--row); otherwise the button beside a trail page's actions.
|
||||
Hidden without JavaScript, which saving needs (.js-only).
|
||||
"""
|
||||
tid = esc(rec["id"])
|
||||
label = f'<span class="vh">Save {name(rec)}</span>'
|
||||
if row:
|
||||
return Markup(f'<button class="save save--row js-only" type="button" data-save="{tid}" '
|
||||
f'aria-pressed="false" title="Save">{ICON_STAR}{label}</button>')
|
||||
return Markup(f'<button class="button button--quiet save save--page js-only" type="button" data-save="{tid}" '
|
||||
f'aria-pressed="false">{ICON_STAR}<span class="save__word" aria-hidden="true">Save</span>{label}</button>')
|
||||
|
||||
|
||||
SWATCH_LINE = Markup('<span class="swatch swatch--line" aria-hidden="true"></span>')
|
||||
SWATCH_ROUTE = Markup('<span class="swatch swatch--route" aria-hidden="true"></span>')
|
||||
SWATCH_ALT = Markup('<span class="swatch swatch--alt" aria-hidden="true"></span>')
|
||||
@@ -218,3 +237,23 @@ ICON_DOWNLOAD = Markup('<svg viewBox="0 0 16 16" aria-hidden="true" focusable="f
|
||||
'<path d="M8 1.5v9M4 7l4 4 4-4M2.5 14.5h11" fill="none" stroke="currentColor" stroke-width="1.6"/></svg>')
|
||||
ICON_EXTERNAL = Markup('<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false">'
|
||||
'<path d="M6 3H3v10h10v-3M9 2.5h4.5V7M13.5 2.5 7 9" fill="none" stroke="currentColor" stroke-width="1.6"/></svg>')
|
||||
# The mark of a saved trail. Its fill is set by style.css (outline when not
|
||||
# saved, filled when saved), so one drawing serves every state.
|
||||
ICON_STAR = Markup('<svg class="star" viewBox="0 0 24 24" aria-hidden="true" focusable="false">'
|
||||
'<path d="M12 2.8l2.85 5.78 6.38.93-4.62 4.5 1.09 6.35L12 17.36l-5.7 3 1.09-6.35-4.62-4.5 '
|
||||
'6.38-.93z" stroke-linejoin="round"/></svg>')
|
||||
# The three themes, for the theme menu in the header: auto (half dark, as the
|
||||
# device decides), light (a sun) and dark (a moon).
|
||||
ICON_THEME = {
|
||||
"auto": Markup('<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">'
|
||||
'<circle cx="12" cy="12" r="8.25" fill="none" stroke="currentColor" stroke-width="1.7"/>'
|
||||
'<path d="M12 3.75a8.25 8.25 0 0 1 0 16.5z" fill="currentColor"/></svg>'),
|
||||
"light": Markup('<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">'
|
||||
'<circle cx="12" cy="12" r="4.25" fill="none" stroke="currentColor" stroke-width="1.7"/>'
|
||||
'<path d="M12 2.5v2.75M12 18.75v2.75M2.5 12h2.75M18.75 12h2.75M5.28 5.28l1.95 1.95'
|
||||
'M16.77 16.77l1.95 1.95M5.28 18.72l1.95-1.95M16.77 7.23l1.95-1.95" fill="none" '
|
||||
'stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/></svg>'),
|
||||
"dark": Markup('<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">'
|
||||
'<path d="M19.75 14.6A8 8 0 0 1 9.4 4.25a8.25 8.25 0 1 0 10.35 10.35z" fill="none" '
|
||||
'stroke="currentColor" stroke-width="1.7" stroke-linejoin="round"/></svg>'),
|
||||
}
|
||||
+55
-13
@@ -121,12 +121,17 @@ def gpx_cell(rec):
|
||||
return f'<span class="line__status">{common.SWATCH_NONE}{esc(facets.GPX_SHORT[status])}</span>'
|
||||
|
||||
|
||||
def entry(rec, *, level=3, extra="", routes_list=False):
|
||||
def entry(rec, *, level=3, extra="", routes_list=False, hidden=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.
|
||||
hidden: written hidden, for app.js to show (the Saved page).
|
||||
|
||||
The Save star follows the name in the markup (so it is the next stop for the
|
||||
keyboard) but is drawn under the logo, out of the row's flow (style.css
|
||||
.save--row): it never makes a row taller or moves its columns.
|
||||
"""
|
||||
route = facets.kind(rec) == "route"
|
||||
lo, hi, est = facets.time_days(rec)
|
||||
@@ -157,10 +162,13 @@ def entry(rec, *, level=3, extra="", routes_list=False):
|
||||
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(climb_m, "stack")}'
|
||||
f'<small class="entry__est">computed</small></dd></div>') if climb_m is not None else ""
|
||||
if hidden:
|
||||
attrs += " hidden"
|
||||
return f"""<li class="entry"{attrs}>
|
||||
{common.plate(rec)}
|
||||
<div class="entry__body">{kicker}
|
||||
<{h} class="entry__name"><a href="{esc(common.trail_path(rec))}">{common.name(rec)}</a>{abbr_html}</{h}>{by}{desc_html}
|
||||
<{h} class="entry__name"><a href="{esc(common.trail_path(rec))}">{common.name(rec)}</a>{abbr_html}</{h}>
|
||||
{common.save_button(rec)}{by}{desc_html}
|
||||
<p class="entry__where">{where_html(rec)}</p>
|
||||
</div>
|
||||
<dl class="entry__facts">
|
||||
@@ -371,14 +379,25 @@ UNITS_TOGGLE = """<fieldset class="results-units">
|
||||
</div>
|
||||
</fieldset>"""
|
||||
|
||||
def sort_select(default_sort="name"):
|
||||
# The order a saved list was made in: offered first on the Saved page only,
|
||||
# where app.js numbers the rows (data-order) in the order they were saved.
|
||||
SAVED_ORDER = ("saved", "Order saved")
|
||||
|
||||
|
||||
def sort_select(default_sort="name", saved=False):
|
||||
"""The one sort control of every list of trails, with the page's
|
||||
default order selected. Hidden without JavaScript (style.css):
|
||||
it cannot work then, and the HTML is already in the default order."""
|
||||
default_sort = facets.normalize_sort(default_sort)
|
||||
it cannot work then, and the HTML is already in the default order.
|
||||
saved: the Saved page's list, which opens in the order saved."""
|
||||
sorts = facets.SORTS
|
||||
if saved:
|
||||
sorts = (SAVED_ORDER,) + tuple(sorts)
|
||||
default_sort = SAVED_ORDER[0]
|
||||
else:
|
||||
default_sort = facets.normalize_sort(default_sort)
|
||||
options = "".join(
|
||||
f'\n <option value="{esc(k)}"{" selected" if k == default_sort else ""}>{esc(label)}</option>'
|
||||
for k, label in facets.SORTS)
|
||||
for k, label in sorts)
|
||||
return f"""<label class="results-sort"><span class="results-sort__label">Sort by</span>
|
||||
<select class="select" id="sort" name="sort" data-sort-select>{options}
|
||||
</select>
|
||||
@@ -398,7 +417,7 @@ def key(official=True):
|
||||
</ul>"""
|
||||
|
||||
|
||||
def results(recs=None, *, finder=False, groups=None, routes_list=False, default_sort="name"):
|
||||
def results(recs=None, *, finder=False, groups=None, routes_list=False, default_sort="name", saved=False):
|
||||
"""The list of trails, as every page shows it: div.results > head, key, list head, ol.entries.
|
||||
|
||||
Every list carries the same "Sort by" control. The rows are written in
|
||||
@@ -410,6 +429,13 @@ def results(recs=None, *, finder=False, groups=None, routes_list=False, default_
|
||||
sorting is within each group and the groups keep their order.
|
||||
extra_fn(rec) gives HTML placed last in each row.
|
||||
routes_list: passed to entry() for the Routes list (see there).
|
||||
saved: the Saved page's list. Every trail's row is written hidden, and
|
||||
app.js shows the saved ones (or a link's) and writes the count; the sort
|
||||
control opens on the order saved.
|
||||
|
||||
A list that holds every trail (the finder's, the Saved page's) is marked
|
||||
data-every-trail: there app.js knows every trail id, and drops the saved
|
||||
ids that match no trail.
|
||||
"""
|
||||
default_sort = facets.normalize_sort(default_sort)
|
||||
if groups is None:
|
||||
@@ -421,14 +447,15 @@ def results(recs=None, *, finder=False, groups=None, routes_list=False, default_
|
||||
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 = ""
|
||||
every = ' data-every-trail' if finder or saved else ""
|
||||
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 "",
|
||||
routes_list=routes_list) for r in items)
|
||||
routes_list=routes_list, hidden=saved) for r in items)
|
||||
if heading:
|
||||
lists += f'\n <h3 class="results__group">{heading}</h3>'
|
||||
list_id = ' id="entries"' if finder else ""
|
||||
lists += f'\n <ol class="entries"{list_id}>\n{rows}\n </ol>'
|
||||
lists += f'\n <ol class="entries"{list_id}{every}>\n{rows}\n </ol>'
|
||||
if finder:
|
||||
count = (f'<p class="results-count" id="results-count" role="status">'
|
||||
f'<strong>{total}</strong> of {total} {noun}</p>')
|
||||
@@ -437,11 +464,15 @@ def results(recs=None, *, finder=False, groups=None, routes_list=False, default_
|
||||
<p><strong>No trails match these filters.</strong></p>
|
||||
<button class="button button--quiet" type="button" data-reset>Clear search and filters</button>
|
||||
</div>"""
|
||||
elif saved:
|
||||
count = '<p class="results-count" data-saved-total><strong>0</strong> trails</p>'
|
||||
empty = ""
|
||||
else:
|
||||
count = f'<p class="results-count"><strong>{total}</strong> {noun}</p>'
|
||||
empty = ""
|
||||
tools = sort_select(default_sort) + "\n " + UNITS_TOGGLE
|
||||
return Markup(f"""<div class="results" data-sortable data-default-sort="{esc(default_sort)}">
|
||||
tools = sort_select(default_sort, saved=saved) + "\n " + UNITS_TOGGLE
|
||||
dflt = SAVED_ORDER[0] if saved else default_sort
|
||||
return Markup(f"""<div class="results" data-sortable data-default-sort="{esc(dflt)}">
|
||||
<div class="results-head">
|
||||
{count}
|
||||
<div class="results-tools">
|
||||
@@ -473,9 +504,15 @@ def drawable_ids(recs):
|
||||
return [r["id"] for r in recs if r["id"] in tracks or hike.sketch_points(r)]
|
||||
|
||||
|
||||
def overview_map(recs, label, *, wide=False, scope=""):
|
||||
def overview_map(recs, label, *, wide=False, scope="", saved=False):
|
||||
"""The map of the given trails (the overview geometry, limited to their ids
|
||||
unless every trail is shown). A note instead when too little can be drawn."""
|
||||
unless every trail is shown). A note instead when too little can be drawn.
|
||||
|
||||
saved: the Saved page's map. It is given every trail (scope "all") and
|
||||
app.js limits it to the trails shown; the figure lists the ids it can draw
|
||||
(data-drawable), so app.js leaves the map out when it would be empty, and
|
||||
its caption counts nothing, since the list is the visitor's.
|
||||
"""
|
||||
ids = drawable_ids(recs)
|
||||
if not ids:
|
||||
return Markup('<p class="note">None of these trails has a GPX here or a known start or end, '
|
||||
@@ -511,6 +548,11 @@ def overview_map(recs, label, *, wide=False, scope=""):
|
||||
f'{"are" if s != 1 else "is"} shown as a dotted straight line between '
|
||||
'their start and end, or a ring where only one end is known. '
|
||||
'That is not the trail’s path.')
|
||||
if saved:
|
||||
sentences = ["Tracks are simplified for display. Select one for its name.",
|
||||
"A trail with no GPX here is shown by its start and end only: dots straight from one "
|
||||
"to the other, or a ring where only one end is known."]
|
||||
ids_attr += f' data-drawable="{esc(" ".join(ids))}"'
|
||||
sentences.append("Each trail’s page names its source, credit and licence. "
|
||||
"Base map: OpenFreeMap, © OpenMapTiles, data © OpenStreetMap contributors.")
|
||||
return Markup(f"""<figure class="mapfig{" mapfig--wide" if wide else ""}" data-map="overview" data-src="/data/overview.geojson"{ids_attr}{overview_bbox(recs)}>
|
||||
|
||||
+60
-20
@@ -54,15 +54,64 @@ def _current(path, href):
|
||||
return href != "/" and path.startswith(href)
|
||||
|
||||
|
||||
SAVED_PATH = "/saved/"
|
||||
|
||||
THEMES = (("auto", "Auto"), ("light", "Light"), ("dark", "Dark"))
|
||||
|
||||
|
||||
def prefs():
|
||||
"""The reader's two display choices, at the right of the header on every page.
|
||||
|
||||
Units: a two-way switch, mi or km first (radios named "units", as every
|
||||
units switch on the site; app.js keeps them in step and fires olt:units).
|
||||
Theme: a small menu built from <details>, its button showing the theme in
|
||||
use (its icon, and its name where there is room); the menu holds the three
|
||||
themes as radios named "theme" (app.js fires olt:theme). The icon and name
|
||||
in the button follow <html data-theme>, which prefs.js sets before first
|
||||
paint, so the button is right from the start. Both need JavaScript and are
|
||||
hidden without it (.js-only).
|
||||
"""
|
||||
icons = "".join(f'<span class="theme__icon theme__icon--{k}">{common.ICON_THEME[k]}</span>' for k, _ in THEMES)
|
||||
now = "".join(f'<span class="theme__now--{k}">{label}</span>' for k, label in THEMES)
|
||||
hint = {"auto": '<span class="vh">, </span><small>As your device is set</small>'}
|
||||
options = "".join(
|
||||
f'<label class="theme__option"><input type="radio" name="theme" value="{k}"{" checked" if k == "auto" else ""}>'
|
||||
f'<span class="theme__choice">{common.ICON_THEME[k]}<span class="theme__label">{label}{hint.get(k, "")}'
|
||||
f'</span></span></label>'
|
||||
for k, label in THEMES)
|
||||
return Markup(f"""<div class="prefs js-only">
|
||||
<fieldset class="prefs__units">
|
||||
<legend class="vh">Units</legend>
|
||||
<div class="seg seg--prefs">
|
||||
<label><input type="radio" name="units" value="mi" checked><span aria-hidden="true">mi</span><span class="vh">Miles and feet</span></label>
|
||||
<label><input type="radio" name="units" value="km"><span aria-hidden="true">km</span><span class="vh">Kilometres and metres</span></label>
|
||||
</div>
|
||||
</fieldset>
|
||||
<details class="theme" data-theme-menu>
|
||||
<summary class="theme__button">{icons}<span class="vh">Theme: </span><span class="theme__now">{now}</span></summary>
|
||||
<fieldset class="theme__menu">
|
||||
<legend class="vh">Theme</legend>
|
||||
{options}
|
||||
</fieldset>
|
||||
</details>
|
||||
</div>""")
|
||||
|
||||
|
||||
def header(path, site):
|
||||
items = "".join(
|
||||
f'<li><a href="{esc(href)}"{attrs(aria_current="page" if path == href else ("true" if _current(path, href) else None))}>'
|
||||
f"{esc(text)}</a></li>"
|
||||
for text, href in NAV)
|
||||
# The visitor's saved trails: app.js fills in the count. Saving needs
|
||||
# JavaScript, so without it the link is not offered.
|
||||
items += (f'<li class="nav__saved js-only"><a href="{SAVED_PATH}"'
|
||||
f'{attrs(aria_current="page" if path == SAVED_PATH else None)}>{common.ICON_STAR}Saved'
|
||||
f'<span class="nav__count" data-saved-count hidden></span></a></li>')
|
||||
return Markup(f"""<header class="site-header">
|
||||
<div class="container site-header__inner">
|
||||
<a class="wordmark" href="/"><img class="wordmark__mark" src="/assets/favicon.svg" alt="" width="28" height="28">{esc(site.name)}</a>
|
||||
<nav aria-label="Main"><ul class="nav">{items}</ul></nav>
|
||||
<nav class="site-nav" aria-label="Main"><ul class="nav">{items}</ul></nav>
|
||||
{prefs()}
|
||||
</div>
|
||||
</header>""")
|
||||
|
||||
@@ -87,6 +136,7 @@ def footer(site):
|
||||
<li><a href="/regions/">Places</a></li>
|
||||
<li><a href="/lists/">Lists</a></li>
|
||||
<li><a href="/routes/">Routes</a></li>
|
||||
<li class="js-only"><a href="{SAVED_PATH}">Saved trails</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
<nav aria-labelledby="footer-project">
|
||||
@@ -99,23 +149,6 @@ def footer(site):
|
||||
{report}
|
||||
</ul>
|
||||
</nav>
|
||||
<div class="site-footer__prefs">
|
||||
<fieldset class="field">
|
||||
<legend>Theme</legend>
|
||||
<div class="seg">
|
||||
<label><input type="radio" name="theme" value="auto" checked><span>Auto</span></label>
|
||||
<label><input type="radio" name="theme" value="light"><span>Light</span></label>
|
||||
<label><input type="radio" name="theme" value="dark"><span>Dark</span></label>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset class="field">
|
||||
<legend>Units</legend>
|
||||
<div class="seg">
|
||||
<label><input type="radio" name="units" value="mi" checked><span>mi and ft first</span></label>
|
||||
<label><input type="radio" name="units" value="km"><span>km and m first</span></label>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
<div class="site-footer__base">
|
||||
<div class="container">{common.FOOTER_MAP_CREDIT}</div>
|
||||
@@ -130,7 +163,7 @@ def _ld_json_block(obj):
|
||||
|
||||
|
||||
def layout(title, body, *, path, description="", maps=False, outdoor=False, scripts=(), data=None, site=None,
|
||||
jsonld=None, og_type="website"):
|
||||
jsonld=None, og_type="website", noindex=False):
|
||||
"""Return a complete HTML document.
|
||||
|
||||
title the page's own title ("Arizona National Scenic Trail"); the site
|
||||
@@ -144,17 +177,23 @@ def layout(title, body, *, path, description="", maps=False, outdoor=False, scri
|
||||
scripts extra same-origin script URLs, loaded with defer after app.js.
|
||||
data optional object, embedded as <script type="application/json" id="page-data">.
|
||||
site settings (olt.site.Site); defaults to web/site.toml.
|
||||
noindex True for a page whose content is the visitor's own (/saved/):
|
||||
search engines are asked not to index it, and it has no
|
||||
canonical address (its address carries the list). seo.py
|
||||
leaves it out of the sitemap.
|
||||
"""
|
||||
site = site or site_settings.load()
|
||||
full_title = f"{title} · {site.name}" if title else f"{site.name}: {site.tagline}"
|
||||
description = description or site.tagline
|
||||
canonical = site.canonical(path)
|
||||
canonical = "" if noindex else site.canonical(path)
|
||||
head = [
|
||||
'<meta charset="utf-8">',
|
||||
'<meta name="viewport" content="width=device-width, initial-scale=1">',
|
||||
f"<title>{esc(full_title)}</title>",
|
||||
f'<meta name="description" content="{esc(description)}">',
|
||||
]
|
||||
if noindex:
|
||||
head.append('<meta name="robots" content="noindex">')
|
||||
if canonical:
|
||||
head.append(f'<link rel="canonical" href="{esc(canonical)}">')
|
||||
head += [
|
||||
@@ -168,6 +207,7 @@ def layout(title, body, *, path, description="", maps=False, outdoor=False, scri
|
||||
]
|
||||
if canonical:
|
||||
head.append(f'<meta property="og:url" content="{esc(canonical)}">')
|
||||
if site.base_url:
|
||||
# A PNG: link previews (Reddit, Slack, iMessage) do not draw an SVG.
|
||||
image = esc(site.canonical("/assets/og.png"))
|
||||
head.append(f'<meta property="og:image" content="{image}">')
|
||||
|
||||
+7
-1
@@ -11,6 +11,7 @@ writes:
|
||||
/regions/, /regions/<slug>/ Places: the hub and one page per state or province
|
||||
/lists/, /lists/<key>/ the lists shown today (olt/browse.py); /routes/ is the Routes list
|
||||
/about/ and the pages under it: /data/, /data/schema/, /data/changelog/, /sources/, /logos/
|
||||
/saved/ the visitor's saved trails (olt/saved.py; not indexed)
|
||||
/404.html not found
|
||||
|
||||
Adding a page elsewhere (regions, sources, ...): build its body as HTML,
|
||||
@@ -21,7 +22,7 @@ import json
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from . import browse, docs, home, layout, regions, seo, site as site_settings, thumbs, trail
|
||||
from . import browse, docs, home, layout, regions, saved, seo, site as site_settings, thumbs, trail
|
||||
|
||||
WEB_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
ASSETS_DIR = os.path.join(WEB_DIR, "assets")
|
||||
@@ -132,6 +133,11 @@ def render_site(records, out_dir, repo_root, site=None):
|
||||
add("/data/schema/", t, d, b)
|
||||
t, d, b = docs.changelog_page(site, repo_root)
|
||||
add("/data/changelog/", t, d, b)
|
||||
# The visitor's own list: not indexed, and left out of the sitemap below.
|
||||
t, d, b = saved.saved_page(records, site)
|
||||
layout.write_page(out_dir, saved.PATH, layout.layout(
|
||||
t, b, path=saved.PATH, description=d, maps=True, site=site, noindex=True))
|
||||
pages += 1
|
||||
docs.copy_licences(out_dir, repo_root)
|
||||
seo.write_seo_files(out_dir, seo.all_paths(records, region_paths + ["/lists/"] + list_paths), site)
|
||||
print(f"pages written {pages}: {len(records)} trail pages, home, 404, places, lists, about")
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
"""The Saved page, /saved/: the visitor's saved trails, or a list opened from a link.
|
||||
|
||||
Saved trails are kept in the visitor's browser only: localStorage, key
|
||||
lh-saved, the trail ids in the order saved (app.js). A link carries a list in
|
||||
its own address, /saved/?t=<id>,<id>,..., so it opens the same list on any
|
||||
device, in any browser, with nothing remembered.
|
||||
|
||||
The page is written like every other, so it cannot know the list. It holds
|
||||
every trail's row, hidden (the same rows as the catalogue, about as heavy as
|
||||
the home page's list; the hidden rows' logos are not fetched), and app.js
|
||||
(initSavedPage) shows the right ones:
|
||||
|
||||
own list no t= in the address: the visitor's saved trails, the map
|
||||
of them, and the link to them with a Copy link button
|
||||
nothing saved no t=, nothing saved: how to save a trail, and a link to the trails
|
||||
from a link t= in the address: that list, marked as from a link, with
|
||||
"Save these" (adds it to the visitor's own) and a way to
|
||||
their own list; ids that match no trail are dropped and
|
||||
counted. A link holding the visitor's own list is shown as theirs.
|
||||
|
||||
Without JavaScript the page says that saved trails need it. It is not
|
||||
indexed (layout noindex) and not in the sitemap (seo.all_paths).
|
||||
"""
|
||||
from . import common, home
|
||||
from .markup import Markup
|
||||
|
||||
PATH = "/saved/"
|
||||
TITLE = "Saved trails"
|
||||
DESCRIPTION = "The trails you saved, kept in this browser, and a link that opens the same list anywhere."
|
||||
|
||||
|
||||
def saved_page(records, site):
|
||||
"""(title, description, body) for /saved/."""
|
||||
recs = sorted(records, key=home.sort_name)
|
||||
star = common.ICON_STAR
|
||||
body = f"""<div class="page-head saved-head" data-saved-page>
|
||||
<div class="container">
|
||||
<header class="titleblock"><div class="titleblock__text">
|
||||
<h1 data-saved-title>{TITLE}</h1>
|
||||
<p class="page-head__lede" data-saved-lede>Trails you save are kept here, in this browser on this device.</p>
|
||||
</div></header>
|
||||
<div class="notice saved-nojs"><p>Saved trails need JavaScript, which is off or blocked in this browser. <a href="/">See every trail</a>.</p></div>
|
||||
<div class="notice saved-from" data-saved-from hidden>
|
||||
<p><strong>This list came from a link.</strong> Opening it has not changed your own saved trails.</p>
|
||||
<p data-saved-dropped hidden></p>
|
||||
<p class="cluster">
|
||||
<button class="button button--primary" type="button" data-saved-merge>{star}Save these</button>
|
||||
<a class="button button--quiet" href="{PATH}">Your saved trails</a>
|
||||
</p>
|
||||
<p class="saved-status" data-saved-merged role="status"></p>
|
||||
</div>
|
||||
<section class="share" data-saved-share hidden aria-labelledby="share-title">
|
||||
<h2 class="share__title" id="share-title">Link to this list</h2>
|
||||
<p class="share__what">Bookmark it, or send it to another device or another person: it opens this same list in any browser.</p>
|
||||
<div class="share__row">
|
||||
<code class="share__url" id="saved-url" data-saved-url></code>
|
||||
<button class="button button--quiet" type="button" data-copy="#saved-url" data-copy-status="#saved-copied" data-copy-done="Link copied." hidden>Copy link</button>
|
||||
</div>
|
||||
<p class="share__done" id="saved-copied" role="status"></p>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container section saved-body">
|
||||
<div class="empty-state saved-empty" data-saved-empty hidden>
|
||||
<p><strong>Nothing saved yet.</strong></p>
|
||||
<p>To save a trail, select the {star}<span class="vh">star</span> in its row in any list of trails, or Save on the trail’s page.</p>
|
||||
<p><a class="button button--primary" href="/">Find a trail</a></p>
|
||||
</div>
|
||||
<div class="empty-state saved-empty" data-saved-none hidden>
|
||||
<p><strong>None of the trails in this link are on this site.</strong></p>
|
||||
<p><a href="/">See every trail</a>, or <a href="{PATH}">your saved trails</a>.</p>
|
||||
</div>
|
||||
<div class="saved-list" data-saved-list hidden>
|
||||
{home.overview_map(recs, "Map of the trails in this list", wide=True, scope="all", saved=True)}
|
||||
{home.results(recs, saved=True)}
|
||||
</div>
|
||||
</div>"""
|
||||
return TITLE, DESCRIPTION, Markup(body)
|
||||
@@ -181,6 +181,7 @@ def page_head(rec):
|
||||
actions.append(f'<a class="button button--primary" href="#download">{common.ICON_DOWNLOAD}Download the GPX</a>')
|
||||
else:
|
||||
actions.append(f'<a class="button button--quiet" href="#track">GPX: {esc(facets.GPX_STATUS[facets.gpx(rec)])}</a>')
|
||||
actions.append(str(common.save_button(rec, row=False)))
|
||||
tag_html = common.badges(rec)
|
||||
kicker = f'<p class="cluster">{tag_html}</p>' if tag_html else ""
|
||||
lead = lead_line(rec)
|
||||
|
||||
Reference in new issue
Block a user