From 94015cd86b42cb7cd2b23ed46e4901974e1b3d5e Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Sat, 14 Nov 2026 23:52:47 -0700 Subject: [PATCH] Show a trail's other links, and the lists the site was checked against A trail's page lists its [[link]] entries under the main buttons, as "More about this trail": the page's title, then who publishes it. The official site stays the main button. A trail with no official site gets its first link in that place, named by its publisher, and that link is not repeated in the list. The About page shows the README's new "Other lists of long trails" section. Tests updated for the new trail counts, and for there being no trail left that spans a whole country. Co-Authored-By: Claude Fable 5.2 --- web/assets/style.css | 8 +++++ web/olt/docs.py | 2 +- web/olt/trail.py | 27 +++++++++++++++++ web/tests/test_extra.py | 9 +++--- web/tests/test_facets.py | 2 +- web/tests/test_md.py | 4 +-- web/tests/test_pages.py | 62 +++++++++++++++++++++++++++++++++++++-- web/tests/test_records.py | 8 ++--- 8 files changed, 108 insertions(+), 14 deletions(-) diff --git a/web/assets/style.css b/web/assets/style.css index f94a299..c8c8e0c 100644 --- a/web/assets/style.css +++ b/web/assets/style.css @@ -1910,3 +1910,11 @@ a.tag:hover { background: var(--sunken); } .entry { --plate-w: 6rem; gap: var(--space-2) var(--space-4); } } .line__status .swatch { flex: none; } + +.morelinks { margin-block-start: var(--space-4); max-inline-size: 36rem; font-family: var(--font-sans); } +.morelinks h2 { margin-block-end: var(--space-1); font: 700 var(--step--1)/1.3 var(--font-sans); letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-2); } +.morelinks ul { padding: 0; list-style: none; } +.morelinks li { padding-block: 0.2rem; font-size: var(--step--1); line-height: 1.4; } +.morelinks__by { color: var(--ink-2); } +.morelinks small { display: block; color: var(--ink-2); font-size: var(--step--1); line-height: 1.4; } +.morelinks svg { display: inline; inline-size: 0.85em; block-size: 0.85em; vertical-align: -0.1em; } diff --git a/web/olt/docs.py b/web/olt/docs.py index c6241a0..4229605 100644 --- a/web/olt/docs.py +++ b/web/olt/docs.py @@ -288,7 +288,7 @@ def about_page(records, site, repo_root): what = quoted("What this is, and what it is not", "The dataset’s own words") rule = quoted("Inclusion rule", "The rule as the dataset states it") - rest = link_requests(render_sections(readme, site, ["How to use it", "Licences", "Report an error"]), site) + rest = link_requests(render_sections(readme, site, ["How to use it", "Other lists of long trails", "Licences", "Report an error"]), site) contrib = render_doc(read_doc(repo_root, "CONTRIBUTING.md"), site, heading_offset=1) cards = "".join( f'
  • {esc(title)}{esc(what_)}
  • ' diff --git a/web/olt/trail.py b/web/olt/trail.py index 89c6d57..6fd442a 100644 --- a/web/olt/trail.py +++ b/web/olt/trail.py @@ -169,6 +169,11 @@ def page_head(rec): official = official_link(rec) if official: actions.append(f'{esc(official[1])} {common.ICON_EXTERNAL}') + elif more_links(rec): + # No page of its own: the first of the pages about the trail stands in, named by its publisher. + first = more_links(rec)[0] + actions.append(f'' + f'{esc(first["publisher"])} {common.ICON_EXTERNAL}') if rec["derived"].get("downloads"): actions.append(f'{common.ICON_DOWNLOAD}Download the GPX') else: @@ -191,6 +196,7 @@ def page_head(rec):

    {lede}

    {"".join(actions)}

    + {links_panel(rec)} """ @@ -608,6 +614,27 @@ def guide_card(g, i): """ +def more_links(rec): + return [l for l in rec.get("link", []) if isinstance(l, dict) and l.get("url")] + + +def links_panel(rec): + """Other pages about this trail, under the buttons at the head of the page and quieter than them.""" + links = more_links(rec) + # With no official site, the first link stands in for that button and is not repeated here. + if not official_link(rec): + links = links[1:] + if not links: + return "" + items = "".join( + f'
  • {esc(l.get("title", ""))} {common.ICON_EXTERNAL}' + f' {esc(l.get("publisher", ""))}' + + (f'{esc(l["note"])}' if l.get("note") else "") + "
  • " + for l in links) + return (f'') + + def guides_panel(rec): guides = rec.get("guide", []) if not guides: diff --git a/web/tests/test_extra.py b/web/tests/test_extra.py index 75413d3..244b3de 100644 --- a/web/tests/test_extra.py +++ b/web/tests/test_extra.py @@ -59,7 +59,7 @@ class ExtraPagesTest(unittest.TestCase): def test_all_routes_on_routes_page(self): routes = [r for r in self.records if r["derived"]["kind"] == "route"] - self.assertEqual(len(routes), 47) + self.assertEqual(len(routes), 50) page = read_out("routes/index.html") import html as _html text = _html.unescape(page) @@ -125,9 +125,10 @@ class ExtraPagesTest(unittest.TestCase): m = re.search(rf'', home_doc) n = sum(1 for r in self.records if g in facets.place_groups(r)) self.assertEqual(int(m.group(1)) if m else 0, n, g) - self.assertTrue(across) - self.assertIn('id="across-canada"', read_out("regions/index.html")) - self.assertIn('id="canada-wide"', read_out("regions/index.html")) # the old anchor still lands + # No trail spans a whole country now that the Trans Canada Trail is gone; + # the "across" section appears only when one does. + self.assertEqual('id="across-canada"' in read_out("regions/index.html"), bool(across)) + self.assertEqual('id="canada-wide"' in read_out("regions/index.html"), bool(across)) # the old anchor def test_list_pages_share_the_home_list(self): for rel in ("index.html", "regions/us-co/index.html", "routes/index.html", diff --git a/web/tests/test_facets.py b/web/tests/test_facets.py index 61b4435..a086424 100644 --- a/web/tests/test_facets.py +++ b/web/tests/test_facets.py @@ -304,7 +304,7 @@ class BuiltVocabularyTest(unittest.TestCase): def test_about_holds_the_dataset_terms(self): doc = self.read("about/index.html") - for want in ('id="how-trails-are-chosen"', "Held", "Deferred", "Candidate", "Track policy", + for want in ('id="how-trails-are-chosen"', "Held", "Candidate", "Track policy", 'href="/data/"', 'href="/sources/"', 'href="/logos/"', 'id="correct-or-add"'): self.assertIn(want, doc, want) for rel in ("data/index.html", "sources/index.html", "logos/index.html", "data/schema/index.html"): diff --git a/web/tests/test_md.py b/web/tests/test_md.py index 97288d8..a290eab 100644 --- a/web/tests/test_md.py +++ b/web/tests/test_md.py @@ -142,7 +142,7 @@ class SectionsTest(unittest.TestCase): self.assertIn("Inclusion rule", sections) self.assertIn("A long trail here is a named, continuous walking route", sections["Inclusion rule"]) - self.assertEqual(len(sections), 10) + self.assertEqual(len(sections), 11) class ParagraphsTest(unittest.TestCase): @@ -394,7 +394,7 @@ class RealDocumentsTest(unittest.TestCase): counter = TableCounter() counter.feed(md.render(read_doc("README.md"))) counter.close() - self.assertEqual(counter.counts, [131, 47]) + self.assertEqual(counter.counts, [132, 50]) def test_readme_num_class_present(self): self.assertIn('class="num"', md.render(read_doc("README.md"))) diff --git a/web/tests/test_pages.py b/web/tests/test_pages.py index d55387e..8757cec 100644 --- a/web/tests/test_pages.py +++ b/web/tests/test_pages.py @@ -90,7 +90,7 @@ class BuiltSiteTest(unittest.TestCase): def test_one_detail_page_per_record(self): found = [d for d in os.listdir(os.path.join(OUT, "trails")) if os.path.isfile(os.path.join(OUT, "trails", d, "index.html"))] - self.assertEqual(len(self.records), 178) + self.assertEqual(len(self.records), 182) self.assertEqual(sorted(found), sorted(r["id"] for r in self.records)) self.assertTrue(os.path.isfile(os.path.join(OUT, "index.html"))) @@ -175,7 +175,7 @@ class BuiltSiteTest(unittest.TestCase): v = raw.get("verification", {}) if raw["source"].get("line_file") and v.get("verified") and abs(v.get("difference_percent", 0)) > 15: expected.add(rec["id"]) - self.assertEqual(len(expected), 17) + self.assertEqual(len(expected), 19) self.assertIn("voyageur", expected) for rec in self.records: page = self.pages[rec["id"]] @@ -395,6 +395,64 @@ def written_forms(value): class RenderUnitTest(unittest.TestCase): + def test_links_listed_in_order_with_publisher(self): + rec = sample_record("L Trail") + rec["link"] = [ + {"title": "First", "publisher": "Pub One", "url": "https://one.example/a?x=1&y=2", "note": "Maps."}, + {"title": "Second", "publisher": "Pub Two", "url": "https://two.example/b"}] + rec.setdefault("hike", {})["official_url"] = "https://trail.example/" + body = trail.render(rec, site.Site("N", "T"))[2] + self.assertIn("More about this trail", body) + self.assertLess(body.index("First"), body.index("Second")) + self.assertIn('href="https://one.example/a?x=1&y=2"', body) + self.assertIn("Pub One", body) + self.assertIn("Maps.", body) + self.assertEqual(body.count("Maps."), 1) + + def test_stand_in_link_is_not_repeated_in_the_list(self): + rec = sample_record("L Trail") + rec["link"] = [{"title": "First", "publisher": "Pub One", "url": "https://one.example/a"}, + {"title": "Second", "publisher": "Pub Two", "url": "https://two.example/b"}] + body = trail.render(rec, site.Site("N", "T"))[2] + self.assertEqual(body.count('href="https://one.example/a"'), 1) + self.assertIn('href="https://two.example/b"', body) + self.assertNotIn("Official site", body) + rec["link"] = rec["link"][:1] + self.assertNotIn("More about this trail", trail.render(rec, site.Site("N", "T"))[2]) + + def test_no_links_shows_nothing(self): + body = trail.render(sample_record("L Trail"), site.Site("N", "T"))[2] + self.assertNotIn("More about this trail", body) + self.assertNotIn("morelinks", body) + + def test_link_title_and_note_are_escaped(self): + rec = sample_record("L Trail") + rec["link"] = [{"title": "", "publisher": "P", + "url": "https://one.example/", "note": ""}] + body = trail.render(rec, site.Site("N", "T"))[2] + self.assertNotIn("