Stop pages stating false or contradictory things, and fix two phone layout bugs
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
46b27acc9c
commit
b1e3f3fb85
12 files changed
+299
-39
No files matched your search
+28
-1
@@ -214,9 +214,36 @@ def rich(text):
|
||||
return Markup("".join(f"<code>{p}</code>" if i % 2 else p for i, p in enumerate(parts)))
|
||||
|
||||
|
||||
# Services the maintainers search with. A search is a note for maintainers (the record's own notes), not
|
||||
# something a visitor is told on the page.
|
||||
INTERNAL_SERVICE = re.compile(r"\b(Overpass|Nominatim|Geofabrik)\b")
|
||||
|
||||
|
||||
def visitor_text(text):
|
||||
"""text without the sentences that name a maintainers' search service."""
|
||||
parts = re.split(r"(?<=[.!?])\s+", text.strip())
|
||||
return " ".join(p for p in parts if not INTERNAL_SERVICE.search(p))
|
||||
|
||||
|
||||
def not_added_yet(rec):
|
||||
"""True when the record says only that no track has been added yet: a public track exists, or may,
|
||||
and the page must not give a reason of the kind "no track may be passed on"."""
|
||||
src = rec.get("source", {})
|
||||
return src.get("status") == "osm-only" or src.get("line_absent_reason", "").startswith("No track has been added")
|
||||
|
||||
|
||||
def sells_gpx(rec):
|
||||
"""True when a guide the author sells names a GPX or GPS track in what it holds (its format or
|
||||
title); a route sold only as a book or map set has no GPX to sell."""
|
||||
return any(g.get("access") == "purchase" and re.search(r"GPX|GPS", f'{g.get("format", "")} {g.get("title", "")}', re.I)
|
||||
for g in rec.get("guide", []))
|
||||
|
||||
|
||||
def absent_reason_short(rec):
|
||||
"""line_absent_reason without the opening "No line is included." or "No track is included." (the status already says so)."""
|
||||
reason = rec.get("source", {}).get("line_absent_reason", "")
|
||||
reason = visitor_text(rec.get("source", {}).get("line_absent_reason", ""))
|
||||
if not_added_yet(rec):
|
||||
return visitor_text(reason.split(". ")[0].rstrip(".") + ".") if reason else reason
|
||||
return re.sub(r"^No (?:line|track) is included\.\s*", "", reason) or reason
|
||||
|
||||
|
||||
|
||||
@@ -286,6 +286,15 @@ def gpx(rec):
|
||||
return "elsewhere"
|
||||
|
||||
|
||||
def gpx_status_text(rec):
|
||||
"""GPX_STATUS for the trail's page. A route sold only as a book or map set has no GPX to sell, so
|
||||
it is not "Sold by its author" as a GPX is."""
|
||||
status = gpx(rec)
|
||||
if status == "sold" and not common.sells_gpx(rec):
|
||||
return "Not here, sold as a guide"
|
||||
return GPX_STATUS[status]
|
||||
|
||||
|
||||
def gpx_here(rec):
|
||||
return gpx(rec) in ("here", "partial")
|
||||
|
||||
|
||||
+5
-4
@@ -166,8 +166,9 @@ def render_site(records, out_dir, repo_root, site=None):
|
||||
|
||||
pending = [] # (path, title, description, body, add() options): written once every view is known
|
||||
|
||||
def view(path, group, link_label, blurb, built):
|
||||
"""Hold a view page built as (title, description, body, recs...) and note it for /lists/."""
|
||||
def view(path, group, link_label, blurb, built, count=None):
|
||||
"""Hold a view page built as (title, description, body, recs...) and note it for /lists/.
|
||||
count: what the page's tile counts, when that is not the trails it lists (the authors page lists routes)."""
|
||||
t, d, b = built[:3]
|
||||
recs = built[3] if len(built) > 3 and isinstance(built[3], list) else None
|
||||
pending.append((path, t, d, b, {"recs": recs, "maps": 'data-map="overview"' in str(b)}))
|
||||
@@ -175,7 +176,7 @@ def render_site(records, out_dir, repo_root, site=None):
|
||||
layout.UNDER_LISTS.add(path) # its header item is Lists
|
||||
labels[path] = link_label
|
||||
if group:
|
||||
extras.append((group, link_label, blurb, path, len(recs) if recs else 0))
|
||||
extras.append((group, link_label, blurb, path, count if count is not None else len(recs) if recs else 0))
|
||||
|
||||
for c in datafiles.collections(repo_root):
|
||||
built = standing.collection_page(c, records, site)
|
||||
@@ -198,7 +199,7 @@ def render_site(records, out_dir, repo_root, site=None):
|
||||
if authors_built:
|
||||
t, d, b, routes = authors.index_page(records, site, repo_root)
|
||||
view(authors.INDEX, "standing", "Route authors", f"The {len(routes)} routes by who published them, and where.",
|
||||
(t, d, b, routes))
|
||||
(t, d, b, routes), count=len(author_groups))
|
||||
for g in author_groups:
|
||||
t, d, b, needs_map, routes, person = authors.author_page(g, records, site, author_groups)
|
||||
path = authors.path(g)
|
||||
|
||||
@@ -106,12 +106,12 @@ def page(p, records, site, all_pages):
|
||||
</div></div>
|
||||
<div class="container section place">
|
||||
{home.browse_view(home.listing(recs, default_sort=lst.sort, top=2, where=""), home.overview_map(recs, f"Map of the trails in {name}: {lst.title}", place=bounds.place_box(info["key"])),
|
||||
about=summary.facts(recs, records), about_title=f"About these trails in {name}")}
|
||||
about=summary.facts(recs, records, place=(name, [info["key"]])), about_title=f"About these trails in {name}")}
|
||||
<nav class="region-nav" aria-label="Lists"><a href="{esc(browse.path(lst))}">{esc(lst.title)} everywhere</a> · <a href="/lists/">All lists</a></nav>
|
||||
{nav}
|
||||
</div>"""
|
||||
by_length = sorted(recs, key=lambda r: (r["length_km"], r["id"]))
|
||||
first = (f"{count} in {name}, from {common.plain_name(by_length[0])}, {regions._miles(by_length[0])} miles, "
|
||||
f"to {common.plain_name(by_length[-1])}, {regions._miles(by_length[-1])} miles.")
|
||||
first = (f"{count} in {name}, from {common.plain_name(by_length[0])}, {regions.trail_miles(by_length[0], [info["key"]])}, "
|
||||
f"to {common.plain_name(by_length[-1])}, {regions.trail_miles(by_length[-1], [info["key"]])}.")
|
||||
desc = regions._fit([f"{lst.blurb} {first}", f"{lst.noun} in {name}: {first}"])
|
||||
return title, desc, Markup(body), home.has_overview_map(recs)
|
||||
+13
-7
@@ -63,6 +63,12 @@ def _miles(rec):
|
||||
return words.fmt_int(rec["derived"]["length_mi"])
|
||||
|
||||
|
||||
def trail_miles(rec, keys):
|
||||
""""5,008 miles in all" for a trail that also lies outside keys (a place's state keys), "50 miles"
|
||||
for one wholly inside: a place's description never gives a whole trail's length as the place's."""
|
||||
return f"{_miles(rec)} miles" + ("" if summary.wholly_in(rec, keys) else " in all")
|
||||
|
||||
|
||||
def _fit(options, limit=common.DESCRIPTION_LIMIT):
|
||||
"""The first of options (fullest first) that fits; else the last, cut at a word."""
|
||||
return common.cut_at_word(next((o for o in options if len(o) <= limit), options[-1]), limit)
|
||||
@@ -161,14 +167,14 @@ def group_page(g, records, site):
|
||||
</div></div>
|
||||
<div class="container section place">
|
||||
{home.browse_view(home.listing(recs, top=2, where="g:" + g), home.overview_map(recs, f"Map of the trails in {name}", place=group_box(g, by_slug)),
|
||||
about=f"{summary.facts(recs, records)}{summary.details(recs)}", about_title=f"About the trails in {name}")}
|
||||
about=f"{summary.facts(recs, records, place=(name, keys))}{summary.details(recs)}", about_title=f"About the trails in {name}")}
|
||||
{nav}
|
||||
</div>"""
|
||||
title = common.fit_title([f"Long Trails in {name}: {_plural(len(recs), 'Trail')}", f"Long Trails in {name}"], site)
|
||||
by_length = sorted(recs, key=lambda r: (r["length_km"], r["id"]))
|
||||
first = (f"{_plural(len(recs))} in {name} ({words.join_names(i['name'] for i in places)}), from "
|
||||
f"{common.plain_name(by_length[0])}, {_miles(by_length[0])} miles, to {common.plain_name(by_length[-1])}, "
|
||||
f"{_miles(by_length[-1])} miles.")
|
||||
f"{common.plain_name(by_length[0])}, {trail_miles(by_length[0], keys)}, to {common.plain_name(by_length[-1])}, "
|
||||
f"{trail_miles(by_length[-1], keys)}.")
|
||||
gpx = f" {_with_gpx(n_gpx, len(recs))[:1].upper()}{_with_gpx(n_gpx, len(recs))[1:]}." if n_gpx else ""
|
||||
desc = _fit([first + gpx, first, f"{_plural(len(recs))} in {name}.{gpx}"])
|
||||
return title, desc, Markup(body), home.has_overview_map(recs), recs
|
||||
@@ -214,7 +220,7 @@ def region_page(slug, records, site, facet_pages=()):
|
||||
</div></div>
|
||||
<div class="container section place">
|
||||
{home.browse_view(home.listing(recs, top=2, where=""), home.overview_map(recs, f"Map of the trails in {info['name']}", place=bounds.place_box(key)),
|
||||
about=f"{summary.facts(recs, records)}{summary.details(recs)}",
|
||||
about=f"{summary.facts(recs, records, place=(info['name'], [key]))}{summary.details(recs)}",
|
||||
about_title=f"About the trails in {info['name']}")}
|
||||
{nav}
|
||||
</div>"""
|
||||
@@ -236,10 +242,10 @@ def region_page(slug, records, site, facet_pages=()):
|
||||
what = _plural(len(recs), "route")
|
||||
gpx = f" {_with_gpx(n_gpx, len(recs))[:1].upper()}{_with_gpx(n_gpx, len(recs))[1:]}." if n_gpx else ""
|
||||
if len(recs) == 1:
|
||||
first = f"{common.plain_name(longest)}, {_miles(longest)} miles, is the one long trail listed in {name}, {country}."
|
||||
first = f"{common.plain_name(longest)}, {trail_miles(longest, [key])}, is the one long trail listed in {name}, {country}."
|
||||
else:
|
||||
first = (f"{what[:1].upper() + what[1:]} in {name}, {country}, from {common.plain_name(shortest)}, {_miles(shortest)} miles, "
|
||||
f"to {common.plain_name(longest)}, {_miles(longest)} miles.")
|
||||
first = (f"{what[:1].upper() + what[1:]} in {name}, {country}, from {common.plain_name(shortest)}, {trail_miles(shortest, [key])}, "
|
||||
f"to {common.plain_name(longest)}, {trail_miles(longest, [key])}.")
|
||||
desc = _fit([first + gpx, first, f"{what[:1].upper() + what[1:]} in {name}, {country}.{gpx}"])
|
||||
return title, desc, Markup(body), home.has_overview_map(recs)
|
||||
|
||||
|
||||
+26
-5
@@ -56,15 +56,35 @@ def holder_counts(recs, records):
|
||||
return out
|
||||
|
||||
|
||||
def facts(recs, records, by_authors=True):
|
||||
def wholly_in(rec, keys):
|
||||
"""True when every state or province the record names is one of keys (olt/facets.py place keys).
|
||||
A trail that names a place outside them only passes through, so its length and high point are
|
||||
not the place's. The record names whole states, never where a trail enters one, so this is the
|
||||
cautious reading."""
|
||||
return set(facets.place_keys(rec)) <= set(keys)
|
||||
|
||||
|
||||
def facts(recs, records, by_authors=True, place=None):
|
||||
"""The summary of a set of trails: one short paragraph (Markup). Empty for no trails. With
|
||||
by_authors False (an author's own page) the routes-and-authors clause is left out."""
|
||||
by_authors False (an author's own page) the routes-and-authors clause is left out.
|
||||
|
||||
place: (name, keys) on a page for a place, so no figure of a whole trail is given as the place's.
|
||||
The length of a trail that also lies elsewhere is said to be its length "in all", and the highest
|
||||
point is taken only from the trails wholly in the place (a high point on file has no location)."""
|
||||
if not recs:
|
||||
return Markup("")
|
||||
by_length = sorted(recs, key=lambda r: (r["length_km"], r["id"]))
|
||||
shortest, longest = by_length[0], by_length[-1]
|
||||
name, keys = place if place else ("", ())
|
||||
inside = [r for r in recs if wholly_in(r, keys)] if place else recs
|
||||
crossing = len(inside) < len(recs)
|
||||
sentences = []
|
||||
if len(recs) > 1:
|
||||
if crossing and len(recs) > 1:
|
||||
sentences.append(f"The longest trail that passes through {esc(name)} is {_name_link(longest)}, {_miles(longest)} in all, "
|
||||
f"and the shortest {_name_link(shortest)}, {_miles(shortest)} in all.")
|
||||
elif crossing:
|
||||
sentences.append(f"{_name_link(longest)} passes through {esc(name)} and is {_miles(longest)} long in all.")
|
||||
elif len(recs) > 1:
|
||||
sentences.append(f"The longest is {_name_link(longest)}, {_miles(longest)}, "
|
||||
f"and the shortest {_name_link(shortest)}, {_miles(shortest)}.")
|
||||
else:
|
||||
@@ -87,10 +107,11 @@ def facts(recs, records, by_authors=True):
|
||||
shown = _join(
|
||||
f'{_list_link(records, "terrain-" + t, words.TERRAIN[t].lower(), n)}' for t, n in terrain[:3])
|
||||
sentences.append(f"The most common terrain is {shown}.")
|
||||
high = [(hike.table(r).get("high_point_m"), r) for r in recs if isinstance(hike.table(r).get("high_point_m"), (int, float))]
|
||||
high = [(hike.table(r).get("high_point_m"), r) for r in inside if isinstance(hike.table(r).get("high_point_m"), (int, float))]
|
||||
if high:
|
||||
m, top = max(high, key=lambda t: (t[0], t[1]["id"]))
|
||||
sentences.append(f"The highest point on file is {words.elevation(m)}, on {_name_link(top)}.")
|
||||
which = f"The highest point on file among the trails wholly in {esc(name)}" if crossing else "The highest point on file"
|
||||
sentences.append(f"{which} is {words.elevation(m)}, on {_name_link(top)}.")
|
||||
return Markup(f"<p>{' '.join(sentences)}</p>")
|
||||
|
||||
|
||||
|
||||
+28
-15
@@ -199,6 +199,14 @@ GPX_CLAUSE = {
|
||||
}
|
||||
|
||||
|
||||
def gpx_clause(rec):
|
||||
"""The clause of the "In brief" paragraph about the GPX; "" when the status has none."""
|
||||
status = facets.gpx(rec)
|
||||
if status == "sold" and not common.sells_gpx(rec):
|
||||
return "its author sells it as a guide, and this site has no GPX for it"
|
||||
return GPX_CLAUSE.get(status, "")
|
||||
|
||||
|
||||
def _name_html(rec):
|
||||
"""The name for the start of a sentence: "The Appalachian Trail", with no "The" before a
|
||||
name that has one or is not in English; marked with its language when it is not English."""
|
||||
@@ -361,7 +369,7 @@ def brief_sentences(rec):
|
||||
f"and {esc(climb)}, {esc(how)}."))
|
||||
|
||||
# When to walk it and whether this site has a GPX: one sentence where the season is a plain range.
|
||||
clause = GPX_CLAUSE.get(facets.gpx(rec)) or ("this site has no GPX for it" + (", so see the official site" if official_link(rec) else ""))
|
||||
clause = gpx_clause(rec) or ("this site has no GPX for it" + (", so see the official site" if official_link(rec) else ""))
|
||||
season = season_sentence(rec)
|
||||
if season and not re.search(r"[,;]", season[1]):
|
||||
# "The usual season is May to July, and this page has a GPX of the track to download."
|
||||
@@ -447,7 +455,7 @@ def action_buttons(rec):
|
||||
if rec["derived"].get("downloads"):
|
||||
actions.append(f'<a class="button button--primary trail-actions__gpx" href="#download">{common.ICON_DOWNLOAD}Download the GPX</a>')
|
||||
else:
|
||||
actions.append(f'<a class="button button--quiet trail-actions__gpx" href="#track">GPX: {esc(facets.GPX_STATUS[facets.gpx(rec)])}</a>')
|
||||
actions.append(f'<a class="button button--quiet trail-actions__gpx" href="#track">GPX: {esc(facets.gpx_status_text(rec))}</a>')
|
||||
official = official_link(rec)
|
||||
if official:
|
||||
actions.append(f'<a class="button button--link" href="{esc(official[0])}">{esc(official[1])} {common.ICON_EXTERNAL}</a>')
|
||||
@@ -601,11 +609,11 @@ def glance(rec, records=None):
|
||||
rows.append(glance_row(facets.WHERE, Markup(f'{region_names(rec)}, {esc(country)}'), wide=True))
|
||||
status = facets.gpx(rec)
|
||||
if facets.gpx_here(rec):
|
||||
text = facets.GPX_STATUS[status]
|
||||
text = facets.gpx_status_text(rec)
|
||||
value = Markup(f'<a href="#download">{esc(text)}</a>') if rec["derived"].get("downloads") else text
|
||||
note = common.partial_short_text(rec) if common.line_differs(rec) else ""
|
||||
else:
|
||||
value = Markup(f'<a href="#track">{esc(facets.GPX_STATUS[status])}</a>')
|
||||
value = Markup(f'<a href="#track">{esc(facets.gpx_status_text(rec))}</a>')
|
||||
note = ""
|
||||
rows.append(glance_row(facets.GPX, value, note, wide=True))
|
||||
halves = [i for i, r in enumerate(rows) if 'glance__wide' not in r.split(">", 1)[0]]
|
||||
@@ -730,28 +738,30 @@ def free_guides(rec):
|
||||
|
||||
|
||||
ROUTE_NO_GPX = {
|
||||
# GPX status -> (heading, what this site does about it)
|
||||
# GPX status -> (heading, what this site does about it); "" for nothing to add to the reason.
|
||||
"free": ("Get the GPX from its author",
|
||||
"A GPX is included here only where the author's terms allow passing it on, or where "
|
||||
"OpenStreetMap maps the route. Otherwise the author's own page is the place to get it."),
|
||||
"sold": ("The author sells the route as a guide",
|
||||
"No GPX is included here from any source, OpenStreetMap included, so the author's work is respected."),
|
||||
"sold": ("The author sells the route as a guide", ""),
|
||||
"unpublished": ("The author does not publish a track",
|
||||
"No GPX is included here from any source, OpenStreetMap included, so the author's choice is respected."),
|
||||
"elsewhere": ("No GPX here",
|
||||
"No GPX is included here until it is clear that the author allows it."),
|
||||
}
|
||||
# A route whose author sells a GPX (common.sells_gpx).
|
||||
ROUTE_SOLD_GPX = ("The author sells a GPX",
|
||||
"A GPX that is sold is not passed on here, and OpenStreetMap's version is not used in its place.")
|
||||
|
||||
|
||||
def _no_gpx_parts(rec):
|
||||
"""(title, status, reason, rule, actions_html): why there is no GPX here
|
||||
and where to get one, for the empty frame and the sketch map alike."""
|
||||
src = rec["source"]
|
||||
reason = src.get("line_absent_reason", "")
|
||||
reason = common.visitor_text(src.get("line_absent_reason", ""))
|
||||
actions = []
|
||||
status = facets.gpx(rec)
|
||||
if common.is_route(rec):
|
||||
title, rule = ROUTE_NO_GPX.get(status, ROUTE_NO_GPX["elsewhere"])
|
||||
title, rule = ROUTE_SOLD_GPX if status == "sold" and common.sells_gpx(rec) else ROUTE_NO_GPX.get(status, ROUTE_NO_GPX["elsewhere"])
|
||||
if status == "free" and free_guides(rec):
|
||||
g = free_guides(rec)[0]
|
||||
actions.append(f'<a class="button button--primary" href="{esc(g["url"])}">'
|
||||
@@ -763,7 +773,8 @@ def _no_gpx_parts(rec):
|
||||
else:
|
||||
title = "No GPX here"
|
||||
reason = common.absent_reason_short(rec)
|
||||
rule = "A trail is listed without a GPX when no track for it may be passed on."
|
||||
# "No track may be passed on" is for a trail whose track is held back, not one not added yet.
|
||||
rule = "" if common.not_added_yet(rec) else "A trail is listed without a GPX when no track for it may be passed on."
|
||||
official = official_link(rec)
|
||||
if official:
|
||||
actions.append(f'<a class="button button--link" href="{esc(official[0])}">'
|
||||
@@ -788,15 +799,16 @@ def _no_gpx_parts(rec):
|
||||
def empty_frame(rec):
|
||||
"""The map frame of a trail with no GPX here and no known start or end point."""
|
||||
title, status, reason, rule, actions_html = _no_gpx_parts(rec)
|
||||
rule_html = f'<p class="note">{esc(rule)}</p>' if rule else ""
|
||||
return f"""<figure class="mapfig mapfig--empty detail__map" id="track" aria-labelledby="noline-title">
|
||||
<div class="mapfig__frame">
|
||||
<span class="mapfig__corner mapfig__corner--nw" aria-hidden="true">No GPX here</span>
|
||||
<div class="map map--empty">
|
||||
<div class="map__message">
|
||||
<p class="kicker">GPX: {esc(facets.GPX_STATUS[status])}</p>
|
||||
<p class="kicker">GPX: {esc(facets.gpx_status_text(rec))}</p>
|
||||
<h2 id="noline-title">{esc(title)}</h2>
|
||||
<p class="map__reason">{reason if isinstance(reason, Markup) else common.rich(reason)}</p>
|
||||
<p class="note">{esc(rule)}</p>
|
||||
{rule_html}
|
||||
{actions_html}
|
||||
</div>
|
||||
</div>
|
||||
@@ -828,6 +840,7 @@ def sketch_figure(rec):
|
||||
caption = ("Only the start and the end are shown. There is no track for this trail here, "
|
||||
"and the site does not guess one.")
|
||||
title, status, reason, rule, actions_html = _no_gpx_parts(rec)
|
||||
rule_html = f'<p class="note">{esc(rule)}</p>' if rule else ""
|
||||
reason_html = reason if isinstance(reason, Markup) else common.rich(reason)
|
||||
frame_attr, drawing = sketch_of(box, sketch.trail_features(rec["id"]), route_main=route)
|
||||
rid = esc(rec["id"])
|
||||
@@ -844,10 +857,10 @@ def sketch_figure(rec):
|
||||
</div>
|
||||
<div class="termini-notice">
|
||||
<div class="map__message">
|
||||
<p class="kicker">GPX: {esc(facets.GPX_STATUS[status])}</p>
|
||||
<p class="kicker">GPX: {esc(facets.gpx_status_text(rec))}</p>
|
||||
<h2 id="noline-title">{esc(title)}</h2>
|
||||
<p class="map__reason">{reason_html}</p>
|
||||
<p class="note">{esc(rule)}</p>
|
||||
{rule_html}
|
||||
{actions_html}
|
||||
</div>
|
||||
</div>
|
||||
@@ -1116,7 +1129,7 @@ def listing_note(rec):
|
||||
meaning = words.meaning(words.WAVES, wave)
|
||||
if note:
|
||||
return Markup(f"{esc(meaning)}. The record’s note: “{common.rich(note)}”")
|
||||
return f"{meaning}. The record has no note saying what."
|
||||
return meaning # no note: say no more than the status (tools/validate.py check_held_note catches the gap in the data)
|
||||
|
||||
|
||||
def abbreviation_fact(rec):
|
||||
|
||||
Reference in new issue
Block a user