Invite corrections: links on every page, issue forms, site checks
Each trail's page now offers "Report a problem" (a GitHub form with the record filled in), "Edit this record" and "History". The footer, the home page and About link to the forms for a wrong record and a missing trail, and Logos links to a form for a steward or creator who wants a track or logo removed or re-credited. The links are built only when repo_url in web/site.toml is a github.com repository. .github/ has the three issue forms and a pull request checklist, and the workflow also runs the site's tests and a build, on Python 3.12. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
1760ae4da9
commit
30c306ecc6
13 files changed
+377
-12
No files matched your search
+7
-3
@@ -54,7 +54,7 @@ def _classify(href, site):
|
||||
if key.startswith("licenses/") and key.endswith(".txt"):
|
||||
return "/licences/" + norm.split("/", 1)[1] + (f"#{frag}" if frag else "")
|
||||
if site.repo_url:
|
||||
return f"{site.repo_url}/blob/main/{norm}" + (f"#{frag}" if frag else "")
|
||||
return site.blob_url(norm) + (f"#{frag}" if frag else "")
|
||||
return None
|
||||
|
||||
|
||||
@@ -228,7 +228,7 @@ def logos_page(records, site, repo_root):
|
||||
<div class="titleblock__text"><p class="kicker">Marks</p><h1>Logos</h1>
|
||||
<p class="page-head__lede">Logos are shown only to identify each trail. They belong to their holders.</p>
|
||||
</div></header></div></div>
|
||||
<div class="container section"><div class="prose doc">{notice_html}</div></div>
|
||||
<div class="container section"><div class="prose doc">{notice_html}{f'<p><a href="{esc(site.removal_url)}">Ask for a track or logo to be removed, or its credit changed</a>.</p>' if site.is_github else ""}</div></div>
|
||||
<div class="container section"><div class="section-head"><h2>Every logo in the dataset</h2>
|
||||
<p>{len(with_logo)} records include a logo file.</p></div>
|
||||
<ul class="logo-grid">{cards}</ul>
|
||||
@@ -246,7 +246,11 @@ def about_page(records, site, repo_root):
|
||||
"How to use it", "Report an error", "Licences", "Sources"]), site)
|
||||
contrib = render_doc(read_doc(repo_root, "CONTRIBUTING.md"), site, heading_offset=1)
|
||||
extra = ""
|
||||
if site.issues_url:
|
||||
if site.repo_url and site.is_github:
|
||||
extra = (f'<p><a href="{esc(site.correction_url())}">Report a problem</a> with a record, or '
|
||||
f'<a href="{esc(site.new_trail_url)}">suggest a trail</a> that is missing: '
|
||||
f'short forms, no git needed. Or fix or add a trail yourself in the source repository.</p>')
|
||||
elif site.issues_url:
|
||||
extra = f'<p><a href="{esc(site.issues_url)}">Open an issue</a> to report an error.</p>'
|
||||
if site.repo_url:
|
||||
extra += f'<p>Source repository: <a href="{esc(site.repo_url)}">{esc(site.repo_url)}</a>.</p>'
|
||||
|
||||
@@ -311,12 +311,19 @@ def render(records, site):
|
||||
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.")
|
||||
contribute = ""
|
||||
if site.repo_url:
|
||||
contribute = (f'<p class="hero__caveat">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">
|
||||
<div class="container hero__inner">
|
||||
<p class="kicker">A public dataset · United States and Canada</p>
|
||||
<h1 id="hero-title">{esc(site.tagline)}</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">
|
||||
|
||||
+5
-2
@@ -60,8 +60,11 @@ def header(path, site):
|
||||
|
||||
|
||||
def footer(site):
|
||||
report = (f'<li><a href="{esc(site.issues_url)}">Report an error in a record</a></li>'
|
||||
if site.issues_url else "")
|
||||
report = ""
|
||||
if site.repo_url:
|
||||
report = (f'<li><a href="{esc(site.correction_url())}">Report an error in a record</a></li>'
|
||||
f'<li><a href="{esc(site.new_trail_url)}">Suggest a trail</a></li>'
|
||||
f'<li><a href="{esc(site.repo_url)}">Fix or add a trail</a></li>')
|
||||
return Markup(f"""<footer class="site-footer">
|
||||
<div class="container site-footer__grid">
|
||||
<div class="site-footer__about">
|
||||
|
||||
+69
-2
@@ -1,7 +1,8 @@
|
||||
"""Site-wide settings from web/site.toml (name, tagline, base_url, repo_url, contact_url, name_lang)."""
|
||||
"""Site-wide settings from web/site.toml (name, tagline, base_url, repo_url, repo_branch, contact_url, name_lang)."""
|
||||
import functools
|
||||
import os
|
||||
import tomllib
|
||||
import urllib.parse
|
||||
|
||||
WEB_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
SITE_TOML = os.path.join(WEB_DIR, "site.toml")
|
||||
@@ -10,13 +11,15 @@ SITE_TOML = os.path.join(WEB_DIR, "site.toml")
|
||||
class Site:
|
||||
"""The settings every page needs. Build one with load()."""
|
||||
|
||||
def __init__(self, name, tagline, base_url="", repo_url="", contact_url="", name_lang=None):
|
||||
def __init__(self, name, tagline, base_url="", repo_url="", repo_branch="main",
|
||||
contact_url="", name_lang=None):
|
||||
if not name:
|
||||
raise ValueError("site.toml: name must not be empty")
|
||||
self.name = name
|
||||
self.tagline = tagline
|
||||
self.base_url = base_url.rstrip("/")
|
||||
self.repo_url = repo_url.rstrip("/")
|
||||
self.repo_branch = (repo_branch or "main").strip() or "main"
|
||||
self.contact_url = contact_url.strip()
|
||||
# record id -> language tag of its name ("fr"), for names that are not English
|
||||
self.name_lang = dict(name_lang or {})
|
||||
@@ -30,12 +33,76 @@ class Site:
|
||||
"""Where to report an error, or "" when repo_url is unset."""
|
||||
return self.repo_url + "/issues" if self.repo_url else ""
|
||||
|
||||
@property
|
||||
def is_github(self):
|
||||
"""True when repo_url is a github.com repository (the only host whose
|
||||
edit/history/issue-form URL shapes the site builds)."""
|
||||
return (urllib.parse.urlsplit(self.repo_url).hostname or "").lower() == "github.com"
|
||||
|
||||
def _github_issue_form_url(self, template, params=()):
|
||||
query = urllib.parse.urlencode([("template", template), *params])
|
||||
return f"{self.repo_url}/issues/new?{query}"
|
||||
|
||||
def correction_url(self, trail_id="", name=""):
|
||||
"""Report-a-problem URL: the GitHub correction form prefilled with the
|
||||
trail (fields are prefilled by their form id), else the issues list,
|
||||
else "" when repo_url is unset."""
|
||||
if not self.repo_url:
|
||||
return ""
|
||||
if not self.is_github:
|
||||
return self.issues_url
|
||||
params = []
|
||||
if trail_id:
|
||||
title = f"Correction: {name} ({trail_id})" if name else f"Correction: {trail_id}"
|
||||
params = [("title", title), ("trail", trail_id)]
|
||||
return self._github_issue_form_url("correction.yml", params)
|
||||
|
||||
@property
|
||||
def new_trail_url(self):
|
||||
"""Suggest-a-trail URL: the GitHub new-trail form, else the issues list, else ""."""
|
||||
if not self.repo_url:
|
||||
return ""
|
||||
if not self.is_github:
|
||||
return self.issues_url
|
||||
return self._github_issue_form_url("new-trail.yml")
|
||||
|
||||
@property
|
||||
def removal_url(self):
|
||||
"""Track/logo removal URL: the GitHub removal form, else the issues list, else ""."""
|
||||
if not self.repo_url:
|
||||
return ""
|
||||
if not self.is_github:
|
||||
return self.issues_url
|
||||
return self._github_issue_form_url("removal.yml")
|
||||
|
||||
def edit_url(self, trail_id):
|
||||
"""GitHub edit URL for <id>/trail.toml, or "" for any other host / no repo."""
|
||||
if not self.is_github:
|
||||
return ""
|
||||
branch = urllib.parse.quote(self.repo_branch, safe="/")
|
||||
return f"{self.repo_url}/edit/{branch}/{urllib.parse.quote(trail_id, safe='')}/trail.toml"
|
||||
|
||||
def history_url(self, trail_id):
|
||||
"""GitHub commit-history URL for <id>/, or "" for any other host / no repo."""
|
||||
if not self.is_github:
|
||||
return ""
|
||||
branch = urllib.parse.quote(self.repo_branch, safe="/")
|
||||
return f"{self.repo_url}/commits/{branch}/{urllib.parse.quote(trail_id, safe='')}"
|
||||
|
||||
def blob_url(self, path):
|
||||
"""Repository URL of a file at repo_branch, or "" when repo_url is unset."""
|
||||
if not self.repo_url:
|
||||
return ""
|
||||
branch = urllib.parse.quote(self.repo_branch, safe="/")
|
||||
return f"{self.repo_url}/blob/{branch}/{path.lstrip('/')}"
|
||||
|
||||
|
||||
def from_file(path):
|
||||
with open(path, "rb") as f:
|
||||
data = tomllib.load(f)
|
||||
return Site(name=data.get("name", ""), tagline=data.get("tagline", ""),
|
||||
base_url=data.get("base_url", ""), repo_url=data.get("repo_url", ""),
|
||||
repo_branch=data.get("repo_branch", "main"),
|
||||
contact_url=data.get("contact_url", ""), name_lang=data.get("name_lang", {}))
|
||||
|
||||
|
||||
|
||||
+12
-2
@@ -653,8 +653,18 @@ def correction_block(rec, site):
|
||||
<h3>If you made this route</h3>
|
||||
<p>A route’s creator can ask for its record to be corrected or removed, and the record will be corrected or removed. Say which route: {code(rec["id"])}. See <a href="/about/">About</a>.</p>
|
||||
</div>""")
|
||||
if site.issues_url:
|
||||
parts.append(f"""<p class="prose">Found an error? <a href="{esc(site.issues_url)}">Open an issue</a> with the record ID ({code(rec["id"])}), what is wrong, and where the correct information can be checked: a source page, a map, or a measured line.</p>""")
|
||||
if site.is_github:
|
||||
report = esc(site.correction_url(rec["id"], rec.get("name", "")))
|
||||
edit = esc(site.edit_url(rec["id"]))
|
||||
history = esc(site.history_url(rec["id"]))
|
||||
parts.append(f"""<p class="prose">This record is a text file anyone can correct. Please say where a correction can be checked: a source page, a map, or a measured track.</p>
|
||||
<ul class="linklist">
|
||||
<li><a href="{report}">Report a problem</a><small>No git needed: a short form, with this record ({code(rec["id"])}) filled in</small></li>
|
||||
<li><a href="{edit}">Edit this record</a><small>The record file (trail.toml) on GitHub</small></li>
|
||||
<li><a href="{history}">History</a><small>Changes to this record on GitHub</small></li>
|
||||
</ul>""")
|
||||
elif site.repo_url:
|
||||
parts.append(f"""<p class="prose">Found an error? Report it in the <a href="{esc(site.repo_url)}">source repository</a>, with the record ID ({code(rec["id"])}), what is wrong, and where the correct information can be checked: a source page, a map, or a measured track.</p>""")
|
||||
if not parts:
|
||||
return ""
|
||||
return block("correct-title", "Corrections", Markup("".join(parts)))
|
||||
|
||||
Reference in new issue
Block a user