Link a breadcrumb's group to the group's own page
The group crumb on a trail page went to an anchor on the places index; it now goes to /regions/<group>/, as the state and province pages do. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
fd7e0302ca
commit
9e435fa2a4
4 files changed
+38
-3
No files matched your search
+2
-2
@@ -8,7 +8,7 @@ import os
|
||||
import re
|
||||
import urllib.parse
|
||||
|
||||
from . import browse, common, elevation, facets, hike, related, seo, sketch, words
|
||||
from . import browse, common, elevation, facets, hike, regions, related, seo, sketch, words
|
||||
from .layout import OUTDOOR_STYLE
|
||||
from .markup import Markup, esc
|
||||
|
||||
@@ -405,7 +405,7 @@ def page_head(rec, author_links=None):
|
||||
groups = facets.place_groups(rec)
|
||||
if keys and keys[0] in facets.GROUP_OF:
|
||||
g = facets.GROUP_OF[keys[0]]
|
||||
crumbs.append(f'<li><a href="/regions/#{esc(g)}">{esc(facets.GROUP_NAME[g])}</a></li>')
|
||||
crumbs.append(f'<li><a href="{esc(regions.group_path(g))}">{esc(facets.GROUP_NAME[g])}</a></li>')
|
||||
crumbs.append(f'<li><a href="{esc(facets.place_path(keys[0]))}">{esc(facets.place_name(keys[0]))}</a></li>')
|
||||
elif groups:
|
||||
crumbs.append(f'<li><a href="/regions/#across-canada">{esc(facets.ACROSS_CANADA_NAME)}</a></li>')
|
||||
|
||||
@@ -169,7 +169,7 @@ class PlaceTest(unittest.TestCase):
|
||||
body = trail.render(fake(1, regions=["CO"]), GH)[2]
|
||||
crumbs = body[body.index('<nav class="breadcrumb"'):body.index("</nav>")]
|
||||
self.assertIn('<a href="/regions/">Places</a>', crumbs)
|
||||
self.assertIn('<a href="/regions/#mountain-west">Mountain West</a>', crumbs)
|
||||
self.assertIn('<a href="/regions/mountain-west/">Mountain West</a>', crumbs)
|
||||
self.assertIn('<a href="/regions/us-co/">Colorado</a>', crumbs)
|
||||
|
||||
|
||||
|
||||
@@ -233,6 +233,37 @@ class JsonLdTest(unittest.TestCase):
|
||||
self.assertEqual("geo" in place, bool(built.get("bbox") or h.get("start_lonlat") or h.get("end_lonlat")),
|
||||
rec["id"])
|
||||
|
||||
def test_group_crumbs_go_to_the_group_page(self):
|
||||
from olt import facets
|
||||
names = {facets.GROUP_NAME[g]: g for g in facets.GROUP_NAME}
|
||||
seen_trail = seen_state = 0
|
||||
for path, doc in self.pages.items():
|
||||
if not (path.startswith(("trails/", "regions/")) and path.endswith("index.html")):
|
||||
continue
|
||||
crumbs = visible_crumbs(doc)
|
||||
for text, href in crumbs[:-1]:
|
||||
g = names.get(text)
|
||||
if g is None or not href:
|
||||
continue
|
||||
self.assertEqual(href, regions.group_path(g), path)
|
||||
self.assertIn(regions.group_path(g).strip("/") + "/index.html", self.pages, path)
|
||||
seen_trail += path.startswith("trails/")
|
||||
seen_state += path.startswith("regions/")
|
||||
# ...and the BreadcrumbList item for it is the same address
|
||||
lists = [n for n in nodes_of(doc) if n["@type"] == "BreadcrumbList"]
|
||||
for i, (text, href) in zip(lists[0]["itemListElement"] if lists else [], crumbs):
|
||||
if names.get(i["name"]) and href:
|
||||
self.assertEqual(i["item"], BASE + regions.group_path(names[i["name"]]), path)
|
||||
self.assertGreater(seen_trail, 0)
|
||||
self.assertGreater(seen_state, 0)
|
||||
|
||||
def test_no_page_links_to_a_group_anchor_that_has_a_page(self):
|
||||
from olt import facets
|
||||
for path, doc in self.pages.items():
|
||||
for g in facets.GROUP_NAME:
|
||||
if regions.group_path(g).strip("/") + "/index.html" in self.pages:
|
||||
self.assertNotIn(f'href="/regions/#{g}"', doc, path)
|
||||
|
||||
def test_breadcrumbs_equal_the_visible_ones(self):
|
||||
counted = 0
|
||||
for path, doc in self.pages.items():
|
||||
|
||||
Reference in new issue
Block a user