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)))
|
||||
|
||||
+5
-1
@@ -14,7 +14,11 @@ base_url = "https://longhikes.org"
|
||||
|
||||
# Home of the source repository, for example "https://github.com/owner/repo".
|
||||
# When set, pages link to it for reporting an error. Empty: those links are left out.
|
||||
repo_url = ""
|
||||
# This repository is public on GitHub; that is where issues and pull requests happen.
|
||||
repo_url = "https://github.com/swaits/longhikes"
|
||||
|
||||
# Default branch of the source repository, for edit/history/blob links.
|
||||
repo_branch = "main"
|
||||
|
||||
# Where to write to the maintainers (a contact page or a mailto: address), for
|
||||
# logo removal requests and other questions. When this or repo_url is set, the
|
||||
|
||||
+51
-1
@@ -17,7 +17,7 @@ WEB = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
ROOT = os.path.dirname(WEB)
|
||||
sys.path.insert(0, WEB)
|
||||
|
||||
from olt import layout, pages, records, site, trail, words # noqa: E402
|
||||
from olt import home, layout, pages, records, site, trail, words # noqa: E402
|
||||
|
||||
OUT = os.path.join(WEB, ".cache", "test-site")
|
||||
|
||||
@@ -412,6 +412,56 @@ class RenderUnitTest(unittest.TestCase):
|
||||
self.assertNotIn("/issues", layout.footer(site.Site("N", "T")))
|
||||
self.assertIn("https://example.org/repo/issues", layout.footer(site.Site("N", "T", repo_url="https://example.org/repo")))
|
||||
|
||||
def test_trail_correction_links_github(self):
|
||||
gh = site.Site("N", "T", repo_url="https://github.com/swaits/longhikes")
|
||||
_, _, body, _ = trail.render(sample_record("A & B Trail"), gh)
|
||||
plain = html.unescape(body)
|
||||
self.assertIn("Report a problem", plain)
|
||||
self.assertIn("https://github.com/swaits/longhikes/issues/new?"
|
||||
"template=correction.yml&title=Correction%3A+A+%26+B+Trail+%28x%29&trail=x", plain)
|
||||
self.assertIn("Edit this record", plain)
|
||||
self.assertIn("https://github.com/swaits/longhikes/edit/main/x/trail.toml", plain)
|
||||
self.assertIn("History", plain)
|
||||
self.assertIn("https://github.com/swaits/longhikes/commits/main/x", plain)
|
||||
|
||||
def test_trail_correction_links_github_branch(self):
|
||||
gh = site.Site("N", "T", repo_url="https://github.com/o/r/", repo_branch="dev")
|
||||
block = html.unescape(trail.correction_block(sample_record("X Trail"), gh))
|
||||
self.assertIn("https://github.com/o/r/edit/dev/x/trail.toml", block)
|
||||
self.assertIn("https://github.com/o/r/commits/dev/x", block)
|
||||
|
||||
def test_trail_correction_links_non_github_fall_back_to_repo(self):
|
||||
other = site.Site("N", "T", repo_url="https://example.org/repo")
|
||||
block = html.unescape(trail.correction_block(sample_record("X Trail"), other))
|
||||
self.assertIn('href="https://example.org/repo"', block)
|
||||
self.assertNotIn("template=correction.yml", block)
|
||||
self.assertNotIn("/edit/", block)
|
||||
self.assertNotIn("/commits/", block)
|
||||
self.assertNotIn("Edit this record", block)
|
||||
|
||||
def test_trail_correction_links_empty_repo_url(self):
|
||||
block = trail.correction_block(sample_record("X Trail"), site.Site("N", "T"))
|
||||
self.assertEqual(block, "")
|
||||
self.assertNotIn("github.com", layout.footer(site.Site("N", "T")))
|
||||
self.assertNotIn("Suggest a trail", layout.footer(site.Site("N", "T")))
|
||||
|
||||
def test_footer_and_home_contribute_links_github(self):
|
||||
gh = site.Site("N", "T", repo_url="https://github.com/swaits/longhikes")
|
||||
footer = html.unescape(layout.footer(gh))
|
||||
self.assertIn("Fix or add a trail", footer)
|
||||
self.assertIn('href="https://github.com/swaits/longhikes"', footer)
|
||||
self.assertIn("Suggest a trail", footer)
|
||||
self.assertIn("https://github.com/swaits/longhikes/issues/new?template=new-trail.yml", footer)
|
||||
body = html.unescape(home.render([sample_record("X Trail")], gh))
|
||||
self.assertIn("https://github.com/swaits/longhikes/issues/new?template=new-trail.yml", body)
|
||||
|
||||
def test_footer_contribute_links_non_github_have_no_github_forms(self):
|
||||
other = site.Site("N", "T", repo_url="https://example.org/repo")
|
||||
footer = html.unescape(layout.footer(other))
|
||||
self.assertIn('href="https://example.org/repo"', footer)
|
||||
self.assertNotIn("template=", footer)
|
||||
self.assertNotIn("github.com", footer)
|
||||
|
||||
def test_render_site_on_a_synthetic_record(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
repo, out = os.path.join(tmp, "repo"), os.path.join(tmp, "out")
|
||||
|
||||
Reference in new issue
Block a user