Show an abbreviation only where a trail has one
A trail's page and its row in a list show its abbreviation when the record has one, and nothing when it has none. Trails that share an abbreviation both show it, and a search for it lists them all. A trail with no logo and no abbreviation gets a small neutral mark in its box, where letters used to be made up for it. "About this data" lists the abbreviation with a link to the page where it was seen. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
ae86d5c3cc
commit
e1f4c01aa7
5 files changed
+106
-5
No files matched your search
@@ -441,6 +441,9 @@ body:has(.hero--home) .site-header .wordmark { visibility: hidden; }
|
|||||||
font: 600 var(--step--1) var(--font-mono);
|
font: 600 var(--step--1) var(--font-mono);
|
||||||
letter-spacing: 0.04em;
|
letter-spacing: 0.04em;
|
||||||
}
|
}
|
||||||
|
/* No logo and no abbreviation of its own: the site's mark, small and quiet */
|
||||||
|
.plate--none > span { display: grid; place-items: center; inline-size: 100%; block-size: 100%; }
|
||||||
|
.plate__mark { inline-size: 36%; block-size: auto; opacity: 0.4; }
|
||||||
|
|
||||||
/* Tally: big numbers over small labels, split by hairlines */
|
/* Tally: big numbers over small labels, split by hairlines */
|
||||||
.tally {
|
.tally {
|
||||||
|
|||||||
+8
-2
@@ -157,8 +157,13 @@ def logo_img(rec, alt, eager=False):
|
|||||||
return f'<img src="{esc(src)}" alt="{esc(alt)}"{dims}{loading} decoding="async">'
|
return f'<img src="{esc(src)}" alt="{esc(alt)}"{dims}{loading} decoding="async">'
|
||||||
|
|
||||||
|
|
||||||
|
# The site's own mark (assets/favicon.svg, its mountain) for a plate with no logo and no abbreviation to show.
|
||||||
|
PLATE_MARK = Markup('<svg class="plate__mark" viewBox="0 0 32 32" focusable="false">'
|
||||||
|
'<path d="M3.5 25.5 13 7.5l5.2 9.3 2.9-4.6 7.4 13.3z" fill="currentColor"/></svg>')
|
||||||
|
|
||||||
|
|
||||||
def plate(rec, *, size="", link=False, eager=False, alt=None):
|
def plate(rec, *, size="", link=False, eager=False, alt=None):
|
||||||
"""The logo on a light plate, or a dashed plate with the short name when there is no logo file.
|
"""The logo on a light plate, or a dashed plate when there is no logo file: the trail's abbreviation if it has one, else the site's mark.
|
||||||
|
|
||||||
link: the logo links to the full-size file. eager: not lazy-loaded (the record page header).
|
link: the logo links to the full-size file. eager: not lazy-loaded (the record page header).
|
||||||
alt: the image's text; by default "<name> logo" on a sized plate and "" on a list plate.
|
alt: the image's text; by default "<name> logo" on a sized plate and "" on a list plate.
|
||||||
@@ -174,7 +179,8 @@ def plate(rec, *, size="", link=False, eager=False, alt=None):
|
|||||||
label = "" if alt else f'<span class="vh">Full-size logo: {name(rec)}</span>'
|
label = "" if alt else f'<span class="vh">Full-size logo: {name(rec)}</span>'
|
||||||
img = f'<a href="{esc(url)}">{img}{label}</a>'
|
img = f'<a href="{esc(url)}">{img}{label}</a>'
|
||||||
return Markup(f'<div class="{cls}">{img}</div>')
|
return Markup(f'<div class="{cls}">{img}</div>')
|
||||||
return Markup(f'<div class="{cls} plate--none" aria-hidden="true"><span>{esc(rec.get("short_name", ""))}</span></div>')
|
inner = esc(rec.get("short_name", "")) or PLATE_MARK
|
||||||
|
return Markup(f'<div class="{cls} plate--none" aria-hidden="true"><span>{inner}</span></div>')
|
||||||
|
|
||||||
|
|
||||||
SWATCH_LINE = Markup('<span class="swatch swatch--line" aria-hidden="true"></span>')
|
SWATCH_LINE = Markup('<span class="swatch swatch--line" aria-hidden="true"></span>')
|
||||||
|
|||||||
+3
-1
@@ -131,7 +131,9 @@ def entry(rec, *, level=3, extra="", routes_list=False):
|
|||||||
route = facets.kind(rec) == "route"
|
route = facets.kind(rec) == "route"
|
||||||
lo, hi, est = facets.time_days(rec)
|
lo, hi, est = facets.time_days(rec)
|
||||||
search = " ".join([rec["name"], rec.get("short_name", ""), rec["id"], facets.author(rec)]).lower()
|
search = " ".join([rec["name"], rec.get("short_name", ""), rec["id"], facets.author(rec)]).lower()
|
||||||
|
abbr = rec.get("short_name", "")
|
||||||
abbr_cls = "entry__abbr" if common.shield_url(rec) else "entry__abbr vh"
|
abbr_cls = "entry__abbr" if common.shield_url(rec) else "entry__abbr vh"
|
||||||
|
abbr_html = f' <span class="{abbr_cls}">{esc(abbr)}</span>' if abbr else ""
|
||||||
# The climb a row may show and sort by (facets.row_climb_m): none when the
|
# The climb a row may show and sort by (facets.row_climb_m): none when the
|
||||||
# track covers too little or too much of the trail, so data-climb is empty
|
# track covers too little or too much of the trail, so data-climb is empty
|
||||||
# in exactly the cases where the row hides its climb.
|
# in exactly the cases where the row hides its climb.
|
||||||
@@ -158,7 +160,7 @@ def entry(rec, *, level=3, extra="", routes_list=False):
|
|||||||
return f"""<li class="entry"{attrs}>
|
return f"""<li class="entry"{attrs}>
|
||||||
{common.plate(rec)}
|
{common.plate(rec)}
|
||||||
<div class="entry__body">{kicker}
|
<div class="entry__body">{kicker}
|
||||||
<{h} class="entry__name"><a href="{esc(common.trail_path(rec))}">{common.name(rec)}</a> <span class="{abbr_cls}">{esc(rec.get("short_name", ""))}</span></{h}>{by}{desc_html}
|
<{h} class="entry__name"><a href="{esc(common.trail_path(rec))}">{common.name(rec)}</a>{abbr_html}</{h}>{by}{desc_html}
|
||||||
<p class="entry__where">{where_html(rec)}</p>
|
<p class="entry__where">{where_html(rec)}</p>
|
||||||
</div>
|
</div>
|
||||||
<dl class="entry__facts">
|
<dl class="entry__facts">
|
||||||
|
|||||||
+16
-2
@@ -162,6 +162,8 @@ def page_head(rec):
|
|||||||
crumbs.append(f'<li><a href="/regions/#across-canada">{esc(facets.ACROSS_CANADA_NAME)}</a></li>')
|
crumbs.append(f'<li><a href="/regions/#across-canada">{esc(facets.ACROSS_CANADA_NAME)}</a></li>')
|
||||||
crumbs.append(f'<li aria-current="page">{common.name(rec)}</li>')
|
crumbs.append(f'<li aria-current="page">{common.name(rec)}</li>')
|
||||||
has_plate = bool(common.shield_url(rec))
|
has_plate = bool(common.shield_url(rec))
|
||||||
|
abbr = rec.get("short_name", "")
|
||||||
|
abbr_html = f' <span class="titleblock__abbr">{esc(abbr)}</span>' if abbr else ""
|
||||||
plate = common.plate(rec, size="lg", link=True, eager=True) if has_plate else ""
|
plate = common.plate(rec, size="lg", link=True, eager=True) if has_plate else ""
|
||||||
summary = hike.summary(rec)
|
summary = hike.summary(rec)
|
||||||
lede = common.rich(summary) if summary else fallback_lede(rec)
|
lede = common.rich(summary) if summary else fallback_lede(rec)
|
||||||
@@ -189,7 +191,7 @@ def page_head(rec):
|
|||||||
{plate}
|
{plate}
|
||||||
<div class="titleblock__text">
|
<div class="titleblock__text">
|
||||||
{kicker}
|
{kicker}
|
||||||
<h1>{common.name(rec)} <span class="titleblock__abbr">{esc(rec.get("short_name", ""))}</span></h1>
|
<h1>{common.name(rec)}{abbr_html}</h1>
|
||||||
{f'<p class="titleblock__sub">{common.rich(lead)}</p>' if lead else ""}
|
{f'<p class="titleblock__sub">{common.rich(lead)}</p>' if lead else ""}
|
||||||
{define}
|
{define}
|
||||||
</div>
|
</div>
|
||||||
@@ -754,6 +756,18 @@ def listing_note(rec):
|
|||||||
return f"{meaning}. The record has no note saying what."
|
return f"{meaning}. The record has no note saying what."
|
||||||
|
|
||||||
|
|
||||||
|
def abbreviation_fact(rec):
|
||||||
|
"""The abbreviation with the page it was seen on."""
|
||||||
|
if not rec.get("short_name"):
|
||||||
|
return ""
|
||||||
|
url = rec.get("short_name_url", "")
|
||||||
|
host = re.sub(r"^www\.", "", urllib.parse.urlsplit(url).hostname or "") or url
|
||||||
|
notes = []
|
||||||
|
if url:
|
||||||
|
notes.append(f'Seen in use at <a href="{esc(url)}">{esc(host)}</a>.')
|
||||||
|
return fact("Abbreviation", rec["short_name"], Markup(" ".join(notes)) if notes else "")
|
||||||
|
|
||||||
|
|
||||||
def record_block(rec):
|
def record_block(rec):
|
||||||
k = common.kind(rec)
|
k = common.kind(rec)
|
||||||
tier = rec.get("tier", "")
|
tier = rec.get("tier", "")
|
||||||
@@ -777,7 +791,7 @@ def record_block(rec):
|
|||||||
Markup(f'<div><dt>Where</dt><dd>{where}</dd></div>'),
|
Markup(f'<div><dt>Where</dt><dd>{where}</dd></div>'),
|
||||||
Markup(f'<div><dt>Published length</dt><dd>{words.length(rec["length_km"], "inline", rec["derived"]["length_mi"])}'
|
Markup(f'<div><dt>Published length</dt><dd>{words.length(rec["length_km"], "inline", rec["derived"]["length_mi"])}'
|
||||||
f'<small>{esc(rec.get("length_note", ""))}. A check value, not measured from the track.</small></dd></div>'),
|
f'<small>{esc(rec.get("length_note", ""))}. A check value, not measured from the track.</small></dd></div>'),
|
||||||
fact("Short name", rec.get("short_name", "")),
|
abbreviation_fact(rec),
|
||||||
fact("Record ID", Markup(code(rec["id"])), "Stable: the directory name, never changed"),
|
fact("Record ID", Markup(code(rec["id"])), "Stable: the directory name, never changed"),
|
||||||
]
|
]
|
||||||
return block("record-title", "The record", facts(*rows))
|
return block("record-title", "The record", facts(*rows))
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
"""A trail with an abbreviation shows it, shared or not; a trail without one shows the site's mark.
|
||||||
|
|
||||||
|
Fixtures only; no real trail's abbreviation is pinned.
|
||||||
|
"""
|
||||||
|
import copy
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
WEB = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
sys.path.insert(0, WEB)
|
||||||
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
from olt import common, home, site, trail # noqa: E402
|
||||||
|
from test_pages import sample_record # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
|
def rec(tid, abbr="PCT", *, tier="regional", kind="designated", km=100, name=None):
|
||||||
|
r = copy.deepcopy(sample_record(name or tid))
|
||||||
|
r.update(id=tid, tier=tier, length_km=km)
|
||||||
|
r["derived"]["kind"] = kind
|
||||||
|
r["derived"]["length_mi"] = round(km / 1.609344)
|
||||||
|
if abbr is None:
|
||||||
|
del r["short_name"]
|
||||||
|
else:
|
||||||
|
r["short_name"] = abbr
|
||||||
|
r["short_name_url"] = f"https://www.example.org/{tid}"
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
class PageTest(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.a = rec("a", name="Big Trail")
|
||||||
|
self.b = rec("b", name="Small Trail") # shares the abbreviation: both show it
|
||||||
|
self.none = rec("none", None, name="Plain Trail")
|
||||||
|
self.site = site.Site("N", "T")
|
||||||
|
|
||||||
|
def page(self, r):
|
||||||
|
return trail.render(r, self.site)[2]
|
||||||
|
|
||||||
|
def test_trail_page_shows_it_for_every_trail_that_has_it(self):
|
||||||
|
for r in (self.a, self.b):
|
||||||
|
self.assertRegex(self.page(r), r'<h1>.*<span class="titleblock__abbr">PCT</span>')
|
||||||
|
self.assertNotIn("titleblock__abbr", self.page(self.none))
|
||||||
|
|
||||||
|
def test_list_row_shows_it_for_every_trail_that_has_it(self):
|
||||||
|
for r in (self.a, self.b):
|
||||||
|
self.assertIn('<span class="entry__abbr vh">PCT</span>', home.entry(r))
|
||||||
|
self.assertNotIn("entry__abbr", home.entry(self.none))
|
||||||
|
|
||||||
|
def test_row_search_text_carries_the_abbreviation(self):
|
||||||
|
search = lambda r: re.search(r'data-search="([^"]*)"', home.entry(r)).group(1)
|
||||||
|
self.assertIn("pct", search(self.a))
|
||||||
|
self.assertIn("pct", search(self.b))
|
||||||
|
self.assertNotIn("pct", search(self.none))
|
||||||
|
|
||||||
|
def test_plate_letters_or_the_mark(self):
|
||||||
|
self.assertIn("<span>PCT</span>", common.plate(self.a))
|
||||||
|
plate = common.plate(self.none)
|
||||||
|
self.assertIn('class="plate plate--none" aria-hidden="true"', plate)
|
||||||
|
self.assertIn('class="plate__mark"', plate)
|
||||||
|
self.assertNotIn("<text", plate)
|
||||||
|
|
||||||
|
def test_about_data_lists_it_with_the_page_it_was_seen_on(self):
|
||||||
|
body = self.page(self.a)
|
||||||
|
self.assertIn("<dt>Abbreviation</dt>", body)
|
||||||
|
self.assertIn('Seen in use at <a href="https://www.example.org/a">example.org</a>', body)
|
||||||
|
self.assertNotIn("shown with it", body)
|
||||||
|
|
||||||
|
def test_about_data_has_no_abbreviation_row_without_one(self):
|
||||||
|
self.assertNotIn("<dt>Abbreviation</dt>", self.page(self.none))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in new issue
Block a user