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 <noreply@anthropic.com>
This commit is contained in:
1 parent
5c716c3c62
commit
94015cd86b
8 files changed
+108
-14
No files matched your search
@@ -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; }
|
||||
+1
-1
@@ -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'<li><a href="{esc(href)}">{esc(title)}</a><small>{esc(what_)}</small></li>'
|
||||
|
||||
@@ -169,6 +169,11 @@ def page_head(rec):
|
||||
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>')
|
||||
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'<a class="button button--link" href="{esc(first["url"])}">'
|
||||
f'{esc(first["publisher"])} {common.ICON_EXTERNAL}</a>')
|
||||
if rec["derived"].get("downloads"):
|
||||
actions.append(f'<a class="button button--primary" href="#download">{common.ICON_DOWNLOAD}Download the GPX</a>')
|
||||
else:
|
||||
@@ -191,6 +196,7 @@ def page_head(rec):
|
||||
</header>
|
||||
<p class="trail-lede">{lede}</p>
|
||||
<p class="cluster trail-actions">{"".join(actions)}</p>
|
||||
{links_panel(rec)}
|
||||
</div>
|
||||
</div>"""
|
||||
|
||||
@@ -608,6 +614,27 @@ def guide_card(g, i):
|
||||
</li>"""
|
||||
|
||||
|
||||
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'<li><a href="{esc(l["url"])}">{esc(l.get("title", ""))} {common.ICON_EXTERNAL}</a>'
|
||||
f' <span class="morelinks__by">{esc(l.get("publisher", ""))}</span>'
|
||||
+ (f'<small>{esc(l["note"])}</small>' if l.get("note") else "") + "</li>"
|
||||
for l in links)
|
||||
return (f'<section class="morelinks" aria-labelledby="morelinks-title">'
|
||||
f'<h2 id="morelinks-title">More about this trail</h2><ul>{items}</ul></section>')
|
||||
|
||||
|
||||
def guides_panel(rec):
|
||||
guides = rec.get("guide", [])
|
||||
if not guides:
|
||||
|
||||
@@ -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'<option value="g:{g}">All of {re.escape(name)} \((\d+)\)</option>', 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",
|
||||
|
||||
@@ -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"):
|
||||
|
||||
@@ -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")))
|
||||
|
||||
+60
-2
@@ -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("<small>Maps.</small>", body)
|
||||
self.assertEqual(body.count("<small>Maps.</small>"), 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": "<script>alert(1)</script>", "publisher": "<b>P</b>",
|
||||
"url": "https://one.example/", "note": "<img src=x onerror=1>"}]
|
||||
body = trail.render(rec, site.Site("N", "T"))[2]
|
||||
self.assertNotIn("<script>alert(1)", body)
|
||||
self.assertNotIn("<b>P</b>", body)
|
||||
self.assertNotIn("<img src=x", body)
|
||||
self.assertIn("<script>alert(1)</script>", body)
|
||||
|
||||
def test_links_with_an_official_site_keep_that_button(self):
|
||||
rec = sample_record("L Trail")
|
||||
rec["hike"] = {"official_url": "https://official.example/"}
|
||||
rec["link"] = [{"title": "T", "publisher": "Wiki", "url": "https://wiki.example/t"}]
|
||||
buttons = re.search(r'<p class="cluster trail-actions">.*?</p>', trail.page_head(rec), re.S).group(0)
|
||||
self.assertIn("Official site", buttons)
|
||||
self.assertNotIn("wiki.example", buttons)
|
||||
|
||||
def test_no_official_site_first_link_stands_in_named_by_publisher(self):
|
||||
rec = sample_record("L Trail")
|
||||
rec["link"] = [{"title": "T", "publisher": "Wiki Pub", "url": "https://wiki.example/t"},
|
||||
{"title": "U", "publisher": "Other", "url": "https://other.example/u"}]
|
||||
buttons = re.search(r'<p class="cluster trail-actions">.*?</p>', trail.page_head(rec), re.S).group(0)
|
||||
self.assertIn('href="https://wiki.example/t"', buttons)
|
||||
self.assertIn("Wiki Pub", buttons)
|
||||
self.assertNotIn("other.example", buttons)
|
||||
self.assertNotIn("Official site", buttons)
|
||||
|
||||
def test_names_are_escaped(self):
|
||||
rec = sample_record(name='Trail & "Quotes" <b>bold</b>')
|
||||
_, description, body, _ = trail.render(rec, site.Site("Site & Co", "Tag"))
|
||||
|
||||
@@ -13,10 +13,10 @@ class RecordsTest(unittest.TestCase):
|
||||
cls.recs = records.load_records()
|
||||
|
||||
def test_counts(self):
|
||||
self.assertEqual(len(self.recs), 178)
|
||||
self.assertEqual(sum(r["derived"]["kind"] == "route" for r in self.recs), 47)
|
||||
self.assertEqual(sum(r["derived"]["kind"] == "designated" for r in self.recs), 131)
|
||||
self.assertEqual(sum(r["derived"]["has_line"] for r in self.recs), 97)
|
||||
self.assertEqual(len(self.recs), 182)
|
||||
self.assertEqual(sum(r["derived"]["kind"] == "route" for r in self.recs), 50)
|
||||
self.assertEqual(sum(r["derived"]["kind"] == "designated" for r in self.recs), 132)
|
||||
self.assertEqual(sum(r["derived"]["has_line"] for r in self.recs), 102)
|
||||
|
||||
def test_sorted_by_id(self):
|
||||
ids = [r["id"] for r in self.recs]
|
||||
|
||||
Reference in new issue
Block a user