Say who each route author is, with a biography from the database
authors.toml gains a summary, a biography, the author's own site and the pages each was read on, for people only. An author's page now opens with the name and the summary, shows a joint credit only on the route it applies to, and carries an About section after the routes. People with three or more routes lead the authors page. Organisations get no biography. 35 people have a summary and a biography and 4 a summary only, each statement checked against the page it cites. Wilderness Mindset is recorded as two people. The Sawtooth Wilderness High Route is credited to Eric Poulin, who names himself as the author of Seeking Lost. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
d7fb6483a2
commit
f467fcb560
15 files changed
+1136
-123
No files matched your search
@@ -1547,6 +1547,18 @@ html:not(.js) .list-head__arrow { display: none; }
|
||||
.block > .block__sub { margin-block-start: var(--space-5); }
|
||||
.block__sub + * { margin-block-start: var(--space-2) !important; }
|
||||
.page-head__lede { max-inline-size: 40rem; color: var(--ink-2); font-size: var(--step-1); }
|
||||
/* One quiet line of facts under a lede (an author's routes, their range, their own site). */
|
||||
.page-head__facts {
|
||||
display: flex; flex-wrap: wrap; align-items: baseline;
|
||||
margin-inline-start: -1.1em; clip-path: inset(0 0 0 1.1em);
|
||||
color: var(--ink-2); font: 400 var(--step--1)/1.5 var(--font-sans);
|
||||
}
|
||||
.page-head__facts > span { position: relative; padding-inline-start: 1.1em; }
|
||||
.page-head__facts > span::before { content: "\00B7"; position: absolute; inset-inline-start: 0.4em; }
|
||||
/* On a phone the sentence over such a line is set a step smaller, so the head stays short. */
|
||||
@media (max-width: 40rem) {
|
||||
.page-head__lede:has(+ .page-head__facts) { font-size: var(--step-0); }
|
||||
}
|
||||
|
||||
/* Downloads */
|
||||
.downloads { padding: 0; list-style: none; }
|
||||
@@ -2216,6 +2228,11 @@ a.tag:hover { background: var(--sunken); }
|
||||
.entry__time dd { font: 500 var(--step-0)/1.3 var(--font-sans); }
|
||||
.entry__est { display: block; color: var(--ink-2); font: 400 var(--step--2)/1.3 var(--font-sans); letter-spacing: 0.04em; text-transform: uppercase; }
|
||||
.results__group { margin-block: var(--space-6) var(--space-2); font-size: var(--step-1); }
|
||||
/* A group led by a person (the authors index): the name, then the one sentence that says who they
|
||||
are, set as the start of a short profile rather than a label over the rows. */
|
||||
.results__lead { margin-block: var(--space-6) var(--space-2); max-inline-size: var(--measure); }
|
||||
.results__lead .results__group { margin: 0; font-size: var(--step-2); line-height: 1.2; }
|
||||
.results__intro { margin-block-start: var(--space-1); color: var(--ink-2); font-size: var(--step-0); line-height: 1.45; text-wrap: pretty; }
|
||||
|
||||
/* "What is a route?" beside the Kind line of a route's page */
|
||||
.define { font: 400 var(--step--1)/1.45 var(--font-sans); color: var(--ink-2); }
|
||||
@@ -2399,6 +2416,12 @@ html:not(.js) .saved-body { display: none; }
|
||||
.shelf--author .shelf__more { margin: 0; padding-block-start: var(--space-2); }
|
||||
.author-list { padding: 0; list-style: none; max-inline-size: var(--measure); }
|
||||
.author-list li { padding-block: var(--space-2); border-block-start: 1px dotted var(--rule); line-height: 1.45; overflow-wrap: anywhere; }
|
||||
.author-list__name { font-weight: 600; }
|
||||
.author-list__summary { color: var(--ink-2); font-size: var(--step--1); }
|
||||
.author-list__routes { font-size: var(--step--1); }
|
||||
/* An author's page, after the rows: the bio, then where it was read, in small print. */
|
||||
.author-about__bio { font-size: var(--step-0); }
|
||||
.author-about__sources { color: var(--ink-3); font: 400 var(--step--2)/1.45 var(--font-sans); letter-spacing: 0.02em; }
|
||||
@media (max-width: 40rem) {
|
||||
.shelf--author { grid-template-rows: auto 1fr auto; padding: var(--space-4); }
|
||||
.shelf--author .shelf__items, .shelf--author .shelf__more { display: block; }
|
||||
|
||||
+188
-71
@@ -3,14 +3,19 @@
|
||||
A route's author is the free text of its [route].creator. authors.toml names a person (or an
|
||||
organisation) with each exact credit that names them, so one page can list every route credited
|
||||
to them, in any form. A credit that names two or more people appears under each of them, so the
|
||||
route is on each page, and each page says who else is credited. A credit that authors.toml does
|
||||
not list stands alone as its own author, and is not typed as a person. Where a route is
|
||||
route is on each page, and that route's row says who else is credited. A credit that authors.toml
|
||||
does not list stands alone as its own author, and is not typed as a person. Where a route is
|
||||
published comes from its [[guide]] entries.
|
||||
|
||||
PROMINENT_MIN is the number of routes at which an author is shown at the top of /authors/,
|
||||
in a block of their own, instead of in the alphabetical list below it. Change it here and the
|
||||
page follows: an author who reaches it moves up with no other change.
|
||||
The words about an author (summary, bio, url, and the sources they were read on) are for people
|
||||
only (kind "person", or "people" for a pair or a person known by a blog's name): an organisation's
|
||||
page lists its routes and nothing more.
|
||||
|
||||
PROMINENT_MIN is the number of routes at which a person is shown at the top of /authors/, under
|
||||
their own heading with their routes as rows, instead of in the alphabetical list below it. Change
|
||||
it here and the page follows: a person who reaches it moves up with no other change.
|
||||
"""
|
||||
import datetime
|
||||
import re
|
||||
import urllib.parse
|
||||
|
||||
@@ -21,6 +26,7 @@ INDEX = "/authors/"
|
||||
PROMINENT_MIN = 3
|
||||
NOT_NAMED = "Author not named"
|
||||
TITLE_LIMIT = 60 # the page's own title, before the site name
|
||||
HUMAN = ("person", "people") # the kinds that are people, and may carry a summary and a bio
|
||||
|
||||
|
||||
def slug(name):
|
||||
@@ -28,9 +34,10 @@ def slug(name):
|
||||
|
||||
|
||||
def groups(records, repo_root):
|
||||
"""[{name, slug, kind, credits, routes, others}] for every route author, sorted by name.
|
||||
kind: "person" or "organisation" as authors.toml says, "" for a credit it does not list.
|
||||
others: {route id: [the other authors the route's credit names]}."""
|
||||
"""[{name, slug, kind, entry, credits, routes, others}] for every route author, sorted by name.
|
||||
kind: "person", "people" or "organisation" as authors.toml says, "" for a credit it does not
|
||||
list. entry: the authors.toml entry ({} for none). others: {route id: [the other authors the
|
||||
route's credit names]}."""
|
||||
entries = {a["name"]: a for a in datafiles.authors(repo_root)}
|
||||
named = {} # credit -> [author names in authors.toml order]
|
||||
for a in datafiles.authors(repo_root):
|
||||
@@ -41,8 +48,9 @@ def groups(records, repo_root):
|
||||
credit = facets.author(r) or NOT_NAMED
|
||||
names = named.get(credit) or [credit]
|
||||
for name in names:
|
||||
g = by_name.setdefault(name, {"name": name, "slug": slug(name), "kind": entries.get(name, {}).get("kind", "person") if name in entries else "",
|
||||
"credits": set(), "routes": [], "others": {}})
|
||||
entry = entries.get(name, {})
|
||||
g = by_name.setdefault(name, {"name": name, "slug": slug(name), "kind": entry.get("kind", "person") if entry else "",
|
||||
"entry": entry, "credits": set(), "routes": [], "others": {}})
|
||||
g["credits"].add(credit)
|
||||
g["routes"].append(r)
|
||||
g["others"][r["id"]] = [n for n in names if n != name]
|
||||
@@ -57,9 +65,26 @@ def author_pages(records, repo_root):
|
||||
return [g for g in groups(records, repo_root) if g["name"] != NOT_NAMED]
|
||||
|
||||
|
||||
def is_human(g):
|
||||
"""A person or people, as authors.toml says: not an organisation, and not a credit it does not list."""
|
||||
return g["kind"] in HUMAN
|
||||
|
||||
|
||||
def about(g):
|
||||
"""The words about a person from authors.toml: {summary, bio, url, checked, sources}. Empty for
|
||||
an organisation or a credit with no entry, whatever the file says (the checker refuses it too)."""
|
||||
e = g.get("entry") or {}
|
||||
if not is_human(g):
|
||||
return {}
|
||||
return {"summary": e.get("summary", ""), "bio": e.get("bio", ""), "url": e.get("url", ""),
|
||||
"checked": e.get("checked"), "sources": e.get("source", [])}
|
||||
|
||||
|
||||
def prominent(gs):
|
||||
"""The authors at or above PROMINENT_MIN routes, most routes first, then by name."""
|
||||
return sorted((g for g in gs if len(g["routes"]) >= PROMINENT_MIN), key=lambda g: (-len(g["routes"]), g["name"].lower()))
|
||||
"""The people at or above PROMINENT_MIN routes, most routes first, then by name. Only people
|
||||
lead: an organisation, or a credit with no entry, is never here however many routes it has."""
|
||||
return sorted((g for g in gs if is_human(g) and len(g["routes"]) >= PROMINENT_MIN),
|
||||
key=lambda g: (-len(g["routes"]), g["name"].lower()))
|
||||
|
||||
|
||||
def path(g):
|
||||
@@ -123,6 +148,52 @@ def own_sites(g):
|
||||
return sorted(found.items())
|
||||
|
||||
|
||||
def _host(url):
|
||||
host = urllib.parse.urlparse(url).hostname or url
|
||||
return host[4:] if host.startswith("www.") else host
|
||||
|
||||
|
||||
def own_site(g):
|
||||
"""(text, url) of the author's own site: the entry's url, else the one the records give; None."""
|
||||
url = about(g).get("url")
|
||||
if url:
|
||||
return _host(url), url
|
||||
sites = own_sites(g)
|
||||
return (_host(sites[0][1]), sites[0][1]) if sites else None
|
||||
|
||||
|
||||
def range_text(g):
|
||||
""""5 routes" and "77 to 6,875 miles", or for one route "1 route" and "77 miles" (miles first)."""
|
||||
lengths = [r["derived"]["length_mi"] for r in g["routes"]]
|
||||
lo, hi = words.fmt_int(min(lengths)), words.fmt_int(max(lengths))
|
||||
return _plural(len(lengths), "route"), (f"{hi} miles" if lo == hi else f"{lo} to {hi} miles")
|
||||
|
||||
|
||||
def fact_lede(g):
|
||||
"""The plain sentence of fact an author's page opens with where there is no summary. It names
|
||||
the author and never stands in for them with a pronoun."""
|
||||
routes = g["routes"]
|
||||
if len(routes) == 1:
|
||||
return f"{g['name']} is credited with one route on this site, {common.plain_name(routes[0])}, {_miles(routes[0])}."
|
||||
count, span = range_text(g)
|
||||
return f"{g['name']} is credited with {count} on this site, from {span}."
|
||||
|
||||
|
||||
def with_html(g, rec, by_name):
|
||||
"""A row's author line on an author's page: who else the route is credited to ("With Ryan
|
||||
Jordan", each linked to their page), or "" where the route is this author's alone. The rest of
|
||||
a credit that names no one else in full ("and collaborators") is given as written."""
|
||||
others = g["others"].get(rec["id"], [])
|
||||
if others:
|
||||
names = [f'<a href="{esc(path(by_name[o]))}">{esc(o)}</a>' if o in by_name else esc(o) for o in others]
|
||||
return Markup("With " + words.join_names(names))
|
||||
credit = facets.author(rec) or ""
|
||||
rest = credit.replace(g["name"], "", 1) if g["name"] in credit else ""
|
||||
if " and " in rest:
|
||||
return Markup("With " + esc(rest.split(" and ", 1)[1].strip()))
|
||||
return ""
|
||||
|
||||
|
||||
def _route_line(rec):
|
||||
return f'<a href="{esc(common.trail_path(rec))}">{esc(common.plain_name(rec))}</a> ({esc(words.fmt_int(rec["derived"]["length_mi"]))} miles)'
|
||||
|
||||
@@ -131,18 +202,12 @@ def _route_links(g):
|
||||
return ", ".join(_route_line(r) for r in g["routes"])
|
||||
|
||||
|
||||
def _block(g):
|
||||
"""A prominent author as a card, in the style of the lists index: name, route count, each
|
||||
route with its length (which follows the units switch), and a link to their page."""
|
||||
n = len(g["routes"])
|
||||
items = "".join(f'<li><a href="{esc(common.trail_path(r))}">{esc(common.plain_name(r))}</a>'
|
||||
f'<span class="shelf__len">{words.length(r["length_km"], mi=r["derived"]["length_mi"])}</span></li>'
|
||||
for r in g["routes"])
|
||||
return (f'<li class="shelf shelf--author">\n'
|
||||
f' <h3 class="shelf__title"><a href="{esc(path(g))}">{esc(g["name"])}</a>'
|
||||
f' <span class="shelf__count" title="Routes on this site">{n}</span></h3>\n'
|
||||
f' <ul class="shelf__items">{items}</ul>\n'
|
||||
f' <p class="shelf__more"><a href="{esc(path(g))}">All {n} routes by {esc(g["name"])}</a></p>\n</li>')
|
||||
def _index_item(g):
|
||||
"""An author in the list under the leading ones: the name, the summary where there is one, the routes."""
|
||||
summary = about(g).get("summary")
|
||||
line = f'<p class="author-list__summary">{esc(summary)}</p>' if summary else ""
|
||||
return (f'<li><a class="author-list__name" href="{esc(path(g))}">{esc(g["name"])}</a>{line}'
|
||||
f'<p class="author-list__routes">{_route_links(g)}</p></li>')
|
||||
|
||||
|
||||
def index_page(records, site, repo_root):
|
||||
@@ -150,29 +215,30 @@ def index_page(records, site, repo_root):
|
||||
gs = author_pages(records, repo_root)
|
||||
routes = [r for r in records if facets.kind(r) == "route"]
|
||||
top = prominent(gs)
|
||||
rest = [g for g in gs if g not in top]
|
||||
# The others, alphabetically; organisations last, as plainly as the rest.
|
||||
rest = sorted((g for g in gs if g not in top), key=lambda g: (g["kind"] == "organisation", g["name"].lower()))
|
||||
n_gpx = sum(1 for r in routes if facets.gpx_here(r))
|
||||
lede = f"{len(routes)} long hiking routes, worked out by {len(gs)} authors, each with a page of their own."
|
||||
lede_more = (f"<p>Every author has a page with their routes and where each is published. "
|
||||
f"{n_gpx} of the routes {'has' if n_gpx == 1 else 'have'} a GPX here. {esc(facets.ROUTE_DEFINITION)}</p>")
|
||||
# The authors with the most routes lead the page: each under their own heading, their routes as
|
||||
# the site's rows, with every route on the map beside them. The other authors follow as a list.
|
||||
groups = [(f'<a href="{esc(path(g))}">{esc(g["name"])}</a> <span class="results__n">{_plural(len(g["routes"]), "route")}</span>',
|
||||
g["routes"], regions.route_guides) for g in top]
|
||||
# The people with the most routes lead the page: each under their own name, with the sentence
|
||||
# that says who they are, their routes as the site's rows, and every route on the map beside them.
|
||||
groups = [((f'<a href="{esc(path(g))}">{esc(g["name"])}</a> <span class="results__n">{_plural(len(g["routes"]), "route")}</span>',
|
||||
esc(about(g).get("summary", ""))), g["routes"], regions.route_guides) for g in top]
|
||||
rest_html = ""
|
||||
if rest:
|
||||
items = "\n".join(f'<li><a href="{esc(path(g))}">{esc(g["name"])}</a>, {_route_links(g)}</li>' for g in rest)
|
||||
items = "\n".join(_index_item(g) for g in rest)
|
||||
heading = "Other authors" if top else "All authors"
|
||||
rest_html = f'<ul class="author-list" aria-label="{heading}">\n{items}\n</ul>\n'
|
||||
listing = home.results(groups=groups, routes_list=True, top=2) if top else ""
|
||||
about = (f"<p>{_plural(len(top), 'author')} with {PROMINENT_MIN} or more routes are above, the most routes first. "
|
||||
"A route credited to several people is listed under each of them. An author credited in more than one form is "
|
||||
"listed once, under the name authors.toml gives. Guides marked free are free; the rest are bought from the "
|
||||
"author or publisher.</p>")
|
||||
about_text = (f"<p>{_plural(len(top), 'author')} with {PROMINENT_MIN} or more routes are above, the most routes first. "
|
||||
"A route credited to several people is listed under each of them. An author credited in more than one form is "
|
||||
"listed once, under the name authors.toml gives. Guides marked free are free; the rest are bought from the "
|
||||
"author or publisher.</p>")
|
||||
body = (pagekit.head("Route authors", lede, [("Trails", "/"), ("Lists", "/lists/"), ("Routes", "/routes/")])
|
||||
+ f"""<div class="container section place">
|
||||
<h2 class="vh" id="most-routes">Authors with {PROMINENT_MIN} or more routes</h2>
|
||||
{home.browse_view(listing, home.overview_map(routes, "Map of every route"), about=rest_html + about + lede_more, about_title="Other authors") if top else rest_html}
|
||||
{home.browse_view(listing, home.overview_map(routes, "Map of every route"), about=rest_html + about_text + lede_more, about_title="Other authors") if top else rest_html}
|
||||
<nav class="region-nav" aria-label="Related pages"><a href="/routes/">Routes with their guides</a> ·
|
||||
<a href="/glossary/#route">What a route is</a> · <a href="/lists/">All lists</a></nav>
|
||||
</div>""")
|
||||
@@ -182,58 +248,109 @@ def index_page(records, site, repo_root):
|
||||
return title, desc, Markup(body), routes
|
||||
|
||||
|
||||
def _date_text(value):
|
||||
return value.isoformat() if isinstance(value, datetime.date) else str(value or "")
|
||||
|
||||
|
||||
def source_links(sources):
|
||||
"""Each publisher once, in order of first appearance: one page is a link on the name; more are the
|
||||
name then numbered links, "The Trek (1, 2)"."""
|
||||
pages = {}
|
||||
for x in sources:
|
||||
pages.setdefault(x.get("publisher", ""), []).append(x.get("url", ""))
|
||||
out = []
|
||||
for pub, urls in pages.items():
|
||||
if len(urls) == 1:
|
||||
out.append(f'<a href="{esc(urls[0])}">{esc(pub)}</a>')
|
||||
else:
|
||||
nums = ", ".join(f'<a href="{esc(u)}">{i}</a>' for i, u in enumerate(urls, 1))
|
||||
out.append(f"{esc(pub)} ({nums})")
|
||||
return out
|
||||
|
||||
|
||||
def about_html(g):
|
||||
"""The bio paragraph and, in small print, the pages it was read on and the date it was checked;
|
||||
"" where there is no bio (every organisation)."""
|
||||
a = about(g)
|
||||
if not a.get("bio"):
|
||||
return ""
|
||||
sources = source_links(a["sources"])
|
||||
checked = _date_text(a.get("checked"))
|
||||
small = []
|
||||
if sources:
|
||||
small.append("Read on " + words.join_names(sources) + ".")
|
||||
if checked:
|
||||
small.append(f'Checked <time datetime="{esc(checked)}">{esc(checked)}</time>.')
|
||||
note = f'\n<p class="author-about__sources">{" ".join(small)}</p>' if small else ""
|
||||
return f'<p class="author-about__bio">{esc(a["bio"])}</p>{note}'
|
||||
|
||||
|
||||
def author_page(g, records, site, all_pages):
|
||||
"""(title, description, body, needs_map, routes, jsonld) for /authors/<slug>/."""
|
||||
"""(title, description, body, needs_map, routes, jsonld) for /authors/<slug>/.
|
||||
|
||||
The head is the author's name, the summary sentence that says who they are (or, with none, a
|
||||
plain sentence of fact), and one quiet line: the routes, their range, and the author's own
|
||||
site. The routes follow as the site's rows beside the map; a route credited to others too says
|
||||
so in its own row, and nowhere else. After the rows: the bio, then each route in brief."""
|
||||
routes = g["routes"]
|
||||
n = len(routes)
|
||||
credits = sorted(g["credits"], key=str.lower)
|
||||
lengths = [r["derived"]["length_mi"] for r in routes]
|
||||
if n == 1:
|
||||
lede = f"{esc(g['name'])} is credited with {esc(common.plain_name(routes[0]))}, {esc(_miles(routes[0]))}."
|
||||
name = g["name"]
|
||||
a = about(g)
|
||||
by_name = {x["name"]: x for x in all_pages}
|
||||
site_link = own_site(g)
|
||||
count, span = range_text(g)
|
||||
if a.get("summary"):
|
||||
lede = esc(a["summary"])
|
||||
facts = [esc(count), esc(span)]
|
||||
else:
|
||||
lede = (f"{esc(g['name'])} is credited with {n} routes on this site, from {esc(words.fmt_int(min(lengths)))} "
|
||||
f"to {esc(words.fmt_int(max(lengths)))} miles.")
|
||||
forms = [c for c in credits if c != g["name"]]
|
||||
if forms:
|
||||
lede += " The records credit them as " + words.join_names(f"“{esc(c)}”" for c in forms) + "."
|
||||
sites = own_sites(g)
|
||||
if sites:
|
||||
lede += " Their own page: " + "; ".join(f'<a href="{esc(u)}">{esc(h)}</a>' for h, u in sites) + "."
|
||||
shared = [r for r in routes if g["others"].get(r["id"])]
|
||||
shared_note = ""
|
||||
if shared:
|
||||
by_name = {x["name"]: x for x in all_pages}
|
||||
lines = []
|
||||
for r in shared:
|
||||
people = [f'<a href="{esc(path(by_name[o]))}">{esc(o)}</a>' if o in by_name else esc(o) for o in g["others"][r["id"]]]
|
||||
lines.append(f'{esc(common.plain_name(r))}: also credited to {words.join_names(people)}.')
|
||||
shared_note = "<p>" + " ".join(lines) + "</p>"
|
||||
briefs = "".join(f'<h4><a href="{esc(common.trail_path(r))}">{esc(common.plain_name(r))}</a></h4>\n{trail.brief(r)}\n' for r in routes)
|
||||
lede = esc(fact_lede(g))
|
||||
facts = []
|
||||
if site_link:
|
||||
facts.append(f'<a href="{esc(site_link[1])}">{esc(site_link[0])}</a>')
|
||||
nav_items = [x for x in prominent(all_pages) if x is not g]
|
||||
nav = (f'<nav class="region-nav" aria-label="Authors with the most routes">Authors with the most routes: '
|
||||
+ " · ".join(f'<a href="{esc(path(x))}">{esc(x["name"])}</a> ({len(x["routes"])})' for x in nav_items) + "</nav>") if nav_items else ""
|
||||
more = str(summary.facts(routes, records)) if n >= 3 else ""
|
||||
listing = home.results(groups=[(None, routes, regions.route_guides)], routes_list=True, top=2)
|
||||
about = f"{more}{shared_note}<h3 id=\"in-brief\">{'About the route' if n == 1 else 'About each route'}</h3>{briefs}"
|
||||
body = (pagekit.head(f"Routes by {g['name']}", lede, [("Trails", "/"), ("Lists", "/lists/"), ("Authors", INDEX)])
|
||||
more = str(summary.facts(routes, records, by_authors=False)) if n >= 3 else ""
|
||||
briefs = "".join(f'<h3><a href="{esc(common.trail_path(r))}">{esc(common.plain_name(r))}</a></h3>\n{trail.brief(r)}\n' for r in routes)
|
||||
listing = home.results(groups=[(None, routes, regions.route_guides)], routes_list=True, top=2,
|
||||
by=lambda r: with_html(g, r, by_name))
|
||||
route_title = "About the route" if n == 1 else "About each route"
|
||||
bio = about_html(g)
|
||||
if bio:
|
||||
view = home.browse_view(listing, home.overview_map(routes, f"Map of the routes by {name}"),
|
||||
about=bio, about_title=f"About {name}", about_id="about-author")
|
||||
view += home.about_section(f"{more}{briefs}", route_title, "in-brief")
|
||||
else:
|
||||
view = home.browse_view(listing, home.overview_map(routes, f"Map of the routes by {name}"),
|
||||
about=f"{more}{briefs}", about_title=route_title, about_id="in-brief")
|
||||
kicker = "Route authors" if g["kind"] == "people" and " and " in name else "Route author"
|
||||
body = (pagekit.head(name, lede, [("Trails", "/"), ("Lists", "/lists/"), ("Authors", INDEX)], kicker=kicker, facts=facts)
|
||||
+ f"""<div class="container section place">
|
||||
<h2 class="vh" id="routes">{'The route' if n == 1 else 'The routes'}</h2>
|
||||
{home.browse_view(listing, home.overview_map(routes, f"Map of the routes by {g['name']}"), about=about, about_title=f"About the routes by {g['name']}")}
|
||||
{view}
|
||||
{nav}
|
||||
<nav class="region-nav" aria-label="Related pages"><a href="/routes/">All routes</a> · <a href="{INDEX}">All route authors</a></nav>
|
||||
</div>""")
|
||||
name = g["name"]
|
||||
options = [f"Routes by {name}: {_plural(n, 'Long Hiking Route')}", f"Routes by {name}"]
|
||||
options = ([f"{name}: {common.plain_name(routes[0])}"] if n == 1 else [f"{name}: {_plural(n, 'Long Hiking Route')}"]) \
|
||||
+ [f"{name}, Route Author", name]
|
||||
title = next((o for o in options if len(o) <= TITLE_LIMIT), common.cut_at_word(options[-1], TITLE_LIMIT))
|
||||
desc = regions._fit([f"{_plural(n, 'long hiking route')} by or with {name}, with length, where it runs, usual time and where it is published.",
|
||||
f"{_plural(n, 'route')} by {name}."])
|
||||
return title, desc, Markup(body), home.has_overview_map(routes), routes, person_jsonld(g, site, sites)
|
||||
facts_text = f"{count} on this site, {span}."
|
||||
if a.get("summary"):
|
||||
desc = regions._fit([f"{a['summary']} {facts_text}", a["summary"]])
|
||||
else:
|
||||
desc = regions._fit([f"{fact_lede(g)} With length, where each runs, usual time and where it is published.",
|
||||
fact_lede(g), f"{_plural(n, 'route')} by {name}."])
|
||||
return title, desc, Markup(body), home.has_overview_map(routes), routes, person_jsonld(g, site, site_link)
|
||||
|
||||
|
||||
def person_jsonld(g, site, sites):
|
||||
"""The author as a Person, only where authors.toml says the credit is a person."""
|
||||
def person_jsonld(g, site, site_link=None):
|
||||
"""The author as a Person, only where authors.toml says the entry is one person (not "people",
|
||||
not an organisation, not a credit it does not list): with the summary as its description and
|
||||
the author's own site as its url and sameAs."""
|
||||
if g["kind"] != "person":
|
||||
return None
|
||||
a = about(g)
|
||||
url = site_link[1] if site_link else None
|
||||
node = {"@type": "Person", "@id": seo.url_of(site, path(g)) + "#author", "name": g["name"],
|
||||
"url": sites[0][1] if sites else None, "sameAs": [u for _, u in sites] or None}
|
||||
"description": a.get("summary") or None, "url": url, "sameAs": [url] if url else None}
|
||||
return seo._clean(node)
|
||||
@@ -3,7 +3,7 @@
|
||||
glossary.toml [[term]] the Glossary page (olt/reference.py)
|
||||
collections.toml [[collection]] named sets of trails set side by side (olt/standing.py)
|
||||
[[list]] which lists the home page shows, and in what order (olt/home.py)
|
||||
authors.toml [[author]] route authors credited in more than one form (olt/authors.py)
|
||||
authors.toml [[author]] route authors, and the words about the people among them (olt/authors.py)
|
||||
|
||||
Each is checked by tools/validate.py and described in docs/schema.md. Like left-out.toml, a file
|
||||
is looked for in the repository being built and then in this one, so a test repository without
|
||||
|
||||
+24
-11
@@ -150,7 +150,7 @@ def route_by_html(rec):
|
||||
return Markup(text)
|
||||
|
||||
|
||||
def entry(rec, *, level=3, extra="", routes_list=False, hidden=False, eager=False, lead=None, rank=None, more=()):
|
||||
def entry(rec, *, level=3, extra="", routes_list=False, hidden=False, eager=False, lead=None, rank=None, more=(), by=None):
|
||||
"""One trail in a list. Its data-* attributes drive the filters in app.js.
|
||||
|
||||
level: the heading level of the trail's name. extra: HTML placed last in the row.
|
||||
@@ -162,6 +162,8 @@ def entry(rec, *, level=3, extra="", routes_list=False, hidden=False, eager=Fals
|
||||
figure, or a figure a page compares). rank: the row's place in a ranking (data-rank, and
|
||||
"No. 3" before the figure). more: [(label, HTML)] of further facts, each with its label,
|
||||
after the others on the line of facts (a page that compares a few trails).
|
||||
by(rec) -> HTML: the row's author line in place of "Route by" (an author's page, where it
|
||||
names only the others a route is credited to); "" for none.
|
||||
|
||||
The Save star follows the name in the markup (so it is the next stop for the
|
||||
keyboard) but is drawn under the logo, out of the row's flow (style.css
|
||||
@@ -191,7 +193,8 @@ def entry(rec, *, level=3, extra="", routes_list=False, hidden=False, eager=Fals
|
||||
h = f"h{level}"
|
||||
tag_html = common.badges(rec, route_tag=not routes_list)
|
||||
kicker = f'\n <p class="entry__kicker">{tag_html}</p>' if tag_html else ""
|
||||
by = f'\n <p class="entry__by">{route_by_html(rec)}</p>' if route and not routes_list else ""
|
||||
by_line = by(rec) if by is not None else route_by_html(rec) if route and not routes_list else ""
|
||||
by = f'\n <p class="entry__by">{by_line}</p>' if by_line else ""
|
||||
desc = entry_desc(rec)
|
||||
desc_html = f'\n <p class="entry__desc">{esc(desc)}</p>' if desc else ""
|
||||
time_html = esc(facets.time_text(rec)) + (' <small class="entry__est">estimate</small>' if est else "")
|
||||
@@ -460,7 +463,7 @@ def key(official=True):
|
||||
|
||||
|
||||
def results(recs=None, *, finder=False, groups=None, routes_list=False, default_sort="name", saved=False, top=3,
|
||||
ranked="", lead=None, more=None, tools=True):
|
||||
ranked="", lead=None, more=None, tools=True, by=None):
|
||||
"""The list of trails, as every page shows it: div.results > head, key, list head, ol.entries.
|
||||
|
||||
Every list carries the same "Sort by" control. The rows are written in
|
||||
@@ -469,7 +472,8 @@ def results(recs=None, *, finder=False, groups=None, routes_list=False, default_
|
||||
|
||||
finder: the home page's list, driven by the filters (live count, empty state).
|
||||
groups: [(heading, trails, extra_fn)] to list the trails under headings (level `top`);
|
||||
sorting is within each group and the groups keep their order.
|
||||
sorting is within each group and the groups keep their order. A heading may be a pair
|
||||
(heading HTML, intro HTML): the intro is a sentence under the heading (an author's summary).
|
||||
top: the heading level of a trail's name where the trails are not in groups (and of a
|
||||
group's heading where they are; the names then sit one level lower). 3 under a page's
|
||||
own h2 (the home page); 2 on a page whose h1 is followed directly by the list.
|
||||
@@ -507,9 +511,13 @@ def results(recs=None, *, finder=False, groups=None, routes_list=False, default_
|
||||
routes_list=routes_list, hidden=saved,
|
||||
eager=not saved and seen + i < EAGER_ROWS,
|
||||
lead=lead(r) if lead else None, more=more(r) if more else (),
|
||||
rank=seen + i + 1 if ranked else None) for i, r in enumerate(items))
|
||||
rank=seen + i + 1 if ranked else None, by=by) for i, r in enumerate(items))
|
||||
seen += len(items)
|
||||
if heading:
|
||||
if isinstance(heading, tuple):
|
||||
heading, intro = heading
|
||||
intro = f'<p class="results__intro">{intro}</p>' if intro else ""
|
||||
lists += f'\n <div class="results__lead"><h{top} class="results__group">{heading}</h{top}>{intro}</div>'
|
||||
elif heading:
|
||||
lists += f'\n <h{top} class="results__group">{heading}</h{top}>'
|
||||
list_id = ' id="entries"' if finder else ""
|
||||
lists += f'\n <ol class="entries"{list_id}{every}>\n{rows}\n </ol>'
|
||||
@@ -672,14 +680,19 @@ def browse_view(listing, map_html, *, about="", about_title="", about_id="about-
|
||||
<div class="browse__list">{listing}{map_html}</div>
|
||||
</div>"""
|
||||
if about:
|
||||
grid += f"""
|
||||
<section class="browse-about" aria-labelledby="{esc(about_id)}">
|
||||
<h2 id="{esc(about_id)}">{esc(about_title or "About these trails")}</h2>
|
||||
<div class="prose">{about}</div>
|
||||
</section>"""
|
||||
grid += about_section(about, about_title or "About these trails", about_id)
|
||||
return Markup(grid)
|
||||
|
||||
|
||||
def about_section(html, title, section_id):
|
||||
"""A section of text after the rows, under its own heading (browse_view's about)."""
|
||||
return Markup(f"""
|
||||
<section class="browse-about" aria-labelledby="{esc(section_id)}">
|
||||
<h2 id="{esc(section_id)}">{esc(title)}</h2>
|
||||
<div class="prose">{html}</div>
|
||||
</section>""")
|
||||
|
||||
|
||||
def has_overview_map(recs, scope=""):
|
||||
"""True when overview_map would draw a map of these trails (needs the map library)."""
|
||||
n = len(drawable_ids(recs))
|
||||
|
||||
+6
-3
@@ -5,15 +5,18 @@ from . import words
|
||||
from .markup import Markup, esc
|
||||
|
||||
|
||||
def head(h1, lede_html, crumbs, *, kicker=""):
|
||||
"""The page-head block. crumbs: [(text, href)] leading to this page; lede_html is HTML."""
|
||||
def head(h1, lede_html, crumbs, *, kicker="", facts=()):
|
||||
"""The page-head block. crumbs: [(text, href)] leading to this page; lede_html is HTML.
|
||||
facts: short facts (HTML) set as one quiet line under the lede."""
|
||||
items = "".join(f'<li><a href="{esc(h)}">{esc(t)}</a></li>' for t, h in crumbs)
|
||||
kick = f'<p class="kicker">{esc(kicker)}</p>' if kicker else ""
|
||||
line = "".join(f"<span>{f}</span>" for f in facts if str(f).strip())
|
||||
line = f'\n <p class="page-head__facts">{line}</p>' if line else ""
|
||||
return f"""<div class="page-head"><div class="container">
|
||||
<nav class="breadcrumb" aria-label="Breadcrumb"><ol>{items}<li aria-current="page">{esc(h1)}</li></ol></nav>
|
||||
<header class="titleblock"><div class="titleblock__text">
|
||||
{kick}<h1>{esc(h1)}</h1>
|
||||
<p class="page-head__lede">{lede_html}</p>
|
||||
<p class="page-head__lede">{lede_html}</p>{line}
|
||||
</div></header>
|
||||
</div></div>"""
|
||||
|
||||
|
||||
+4
-3
@@ -56,8 +56,9 @@ def holder_counts(recs, records):
|
||||
return out
|
||||
|
||||
|
||||
def facts(recs, records):
|
||||
"""The summary of a set of trails: one short paragraph (Markup). Empty for no trails."""
|
||||
def facts(recs, records, by_authors=True):
|
||||
"""The summary of a set of trails: one short paragraph (Markup). Empty for no trails. With
|
||||
by_authors False (an author's own page) the routes-and-authors clause is left out."""
|
||||
if not recs:
|
||||
return Markup("")
|
||||
by_length = sorted(recs, key=lambda r: (r["length_km"], r["id"]))
|
||||
@@ -73,7 +74,7 @@ def facts(recs, records):
|
||||
parts = []
|
||||
if loops:
|
||||
parts.append(f"{loops} {'is a loop' if loops == 1 else 'are loops'}")
|
||||
if routes:
|
||||
if routes and by_authors:
|
||||
authors = {facets.author(r) for r in routes if facets.author(r)}
|
||||
n = len(routes)
|
||||
parts.append(f"{n} {'is a route' if n == 1 else 'are routes'}"
|
||||
|
||||
+188
-3
@@ -7,6 +7,9 @@ These do not need the built site.
|
||||
python3 -m unittest discover -s web/tests
|
||||
"""
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import tempfile
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
@@ -225,7 +228,69 @@ class CollectionTest(unittest.TestCase):
|
||||
self.assertIsNone(standing.collection_page(self.coll, self.recs, SITE))
|
||||
|
||||
|
||||
BIO = "Jo Walker has walked " + "a long way " * 20 + "and written guides to it."
|
||||
AUTHORS_FIXTURE = f'''
|
||||
[[author]]
|
||||
name = "Jo Walker"
|
||||
credits = ["Jo Walker", "Jo Walker and Sam Hill"]
|
||||
url = "https://jowalker.example/"
|
||||
summary = "Jo Walker is a hiker who works out long desert routes."
|
||||
bio = "{BIO}"
|
||||
checked = 2026-11-17
|
||||
[[author.source]]
|
||||
url = "https://jowalker.example/about/"
|
||||
publisher = "Jo Walker's site"
|
||||
[[author.source]]
|
||||
url = "https://magazine.example/jo/"
|
||||
publisher = "A Magazine"
|
||||
|
||||
[[author]]
|
||||
name = "Sam Hill"
|
||||
credits = ["Jo Walker and Sam Hill"]
|
||||
|
||||
[[author]]
|
||||
name = "Ann and Bo"
|
||||
kind = "people"
|
||||
credits = ["Ann and Bo"]
|
||||
summary = "Ann and Bo are a couple who hike long routes together."
|
||||
checked = 2026-11-17
|
||||
[[author.source]]
|
||||
url = "https://annandbo.example/"
|
||||
publisher = "Ann and Bo"
|
||||
|
||||
[[author]]
|
||||
name = "Big Club"
|
||||
kind = "organisation"
|
||||
credits = ["Big Club"]
|
||||
summary = "Big Club is a club that the checker would refuse to describe."
|
||||
bio = "{BIO}"
|
||||
'''
|
||||
PRONOUN = re.compile(r"\b(he|she|him|his|her|hers|they|them|their|theirs)\b", re.I)
|
||||
|
||||
|
||||
class AuthorTest(unittest.TestCase):
|
||||
def fixture_root(self):
|
||||
d = tempfile.mkdtemp()
|
||||
self.addCleanup(shutil.rmtree, d)
|
||||
with open(os.path.join(d, "authors.toml"), "w") as f:
|
||||
f.write(AUTHORS_FIXTURE)
|
||||
return d
|
||||
|
||||
def fixture(self, credits):
|
||||
root = self.fixture_root()
|
||||
recs = self.routes(credits)
|
||||
gs = authors.author_pages(recs, root)
|
||||
return recs, root, {g["name"]: g for g in gs}, gs
|
||||
|
||||
def page(self, name, credits):
|
||||
recs, root, by, gs = self.fixture(credits)
|
||||
return authors.author_page(by[name], recs, SITE, gs)
|
||||
|
||||
@staticmethod
|
||||
def head(body):
|
||||
html = str(body)
|
||||
return html[:html.index('class="container section place"')]
|
||||
|
||||
def routes(self, credits):
|
||||
out = []
|
||||
for i, c in enumerate(credits):
|
||||
@@ -249,7 +314,7 @@ class AuthorTest(unittest.TestCase):
|
||||
self.assertEqual(gs["Ryan Jordan"]["others"][recs[0]["id"]], ["Andrew Skurka"])
|
||||
g = gs["Ryan Jordan"]
|
||||
_, _, body, _, _, person = authors.author_page(g, recs, SITE, list(gs.values()))
|
||||
self.assertIn("also credited to <a href=\"/authors/andrew-skurka/\">Andrew Skurka</a>", str(body))
|
||||
self.assertIn('<p class="entry__by">With <a href="/authors/andrew-skurka/">Andrew Skurka</a></p>', str(body))
|
||||
self.assertEqual(person["@type"], "Person")
|
||||
|
||||
def test_featured_authors_lead_the_page_with_their_routes_as_the_site_s_rows(self):
|
||||
@@ -281,7 +346,7 @@ class AuthorTest(unittest.TestCase):
|
||||
self.assertIn('<li class="entry"', str(body))
|
||||
self.assertLessEqual(len(title), 60)
|
||||
self.assertEqual(person["name"], one["name"])
|
||||
club = next(g for g in gs if g["name"] == "Wilderness Mindset")
|
||||
club = next(g for g in gs if g["kind"] == "") # a credit with no entry in authors.toml
|
||||
self.assertEqual(club["kind"], "")
|
||||
self.assertIsNone(authors.author_page(club, real, SITE, gs)[5])
|
||||
|
||||
@@ -291,7 +356,8 @@ class AuthorTest(unittest.TestCase):
|
||||
top = authors.prominent(gs)
|
||||
self.assertTrue(top)
|
||||
self.assertTrue(all(len(g["routes"]) >= authors.PROMINENT_MIN for g in top))
|
||||
self.assertEqual(len(top), sum(1 for g in gs if len(g["routes"]) >= authors.PROMINENT_MIN))
|
||||
self.assertEqual(len(top), sum(1 for g in gs if len(g["routes"]) >= authors.PROMINENT_MIN and authors.is_human(g)))
|
||||
self.assertTrue(all(authors.is_human(g) for g in top)) # only people lead
|
||||
counts = [len(g["routes"]) for g in top]
|
||||
self.assertEqual(counts, sorted(counts, reverse=True))
|
||||
body = str(authors.index_page(real, SITE, ROOT)[2])
|
||||
@@ -320,6 +386,108 @@ class AuthorTest(unittest.TestCase):
|
||||
self.assertIn(c, creators)
|
||||
|
||||
|
||||
def test_the_head_is_the_name_the_summary_and_a_line_of_facts(self):
|
||||
title, desc, body, _, _, _ = self.page("Jo Walker", ["Jo Walker", "Jo Walker", "Jo Walker and Sam Hill"])
|
||||
head = self.head(body)
|
||||
self.assertIn('<p class="kicker">Route author</p><h1>Jo Walker</h1>', head)
|
||||
self.assertIn('<p class="page-head__lede">Jo Walker is a hiker who works out long desert routes.</p>', head)
|
||||
self.assertIn('<p class="page-head__facts"><span>3 routes</span>', head)
|
||||
self.assertIn('<a href="https://jowalker.example/">jowalker.example</a>', head)
|
||||
self.assertNotIn("Routes by", head)
|
||||
self.assertNotIn("Sam Hill", head) # the joint credit is in its row only
|
||||
self.assertNotIn("credit", head.lower())
|
||||
self.assertTrue(desc.startswith("Jo Walker is a hiker"))
|
||||
self.assertLessEqual(len(desc), common.DESCRIPTION_LIMIT)
|
||||
self.assertLessEqual(len(title), authors.TITLE_LIMIT)
|
||||
self.assertTrue(title.startswith("Jo Walker"))
|
||||
|
||||
def test_the_joint_credit_is_named_on_its_row_and_nowhere_else(self):
|
||||
_, _, body, _, _, _ = self.page("Jo Walker", ["Jo Walker", "Jo Walker and Sam Hill"])
|
||||
html = str(body)
|
||||
row = '<p class="entry__by">With <a href="/authors/sam-hill/">Sam Hill</a></p>'
|
||||
self.assertEqual(html.count(row), 1)
|
||||
rows = html[:html.index('class="browse-about"')]
|
||||
self.assertEqual(rows.count("Sam Hill"), 1) # (each route's "In brief" after the rows gives its credit as written)
|
||||
self.assertEqual(html.count('class="entry__by"'), 1) # the route that is Jo's alone has no author line
|
||||
self.assertNotIn("also credited", html)
|
||||
|
||||
def test_the_rest_of_a_credit_that_names_no_one_else_is_given_on_its_row(self):
|
||||
recs = self.routes(["Andrew Skurka", "Andrew Skurka and friends"])
|
||||
g = {"name": "Andrew Skurka", "slug": "andrew-skurka", "kind": "person", "entry": {}, "credits": set(),
|
||||
"routes": recs, "others": {}}
|
||||
self.assertEqual(authors.with_html(g, recs[0], {}), "")
|
||||
self.assertEqual(str(authors.with_html(g, recs[1], {})), "With friends")
|
||||
|
||||
def test_the_about_section_follows_the_rows_with_its_sources(self):
|
||||
_, _, body, _, _, _ = self.page("Jo Walker", ["Jo Walker"])
|
||||
html = str(body)
|
||||
self.assertIn('<h2 id="about-author">About Jo Walker</h2>', html)
|
||||
self.assertLess(html.index('class="entries"'), html.index('id="about-author"'))
|
||||
self.assertLess(html.index('id="about-author"'), html.index('id="in-brief"'))
|
||||
about = html[html.index('id="about-author"'):html.index('id="in-brief"')]
|
||||
self.assertIn(f'<p class="author-about__bio">{BIO}</p>', about.replace("'", "'"))
|
||||
self.assertIn('<a href="https://jowalker.example/about/">Jo Walker's site</a>', about.replace("'", "'"))
|
||||
self.assertIn('<a href="https://magazine.example/jo/">A Magazine</a>', about)
|
||||
self.assertIn('<time datetime="2026-11-17">2026-11-17</time>', about)
|
||||
|
||||
def test_with_no_summary_the_head_is_a_plain_sentence_of_fact_and_no_pronoun(self):
|
||||
for name, credits in (("Sam Hill", ["Jo Walker and Sam Hill", "Jo Walker and Sam Hill"]),
|
||||
("Lone Hiker", ["Lone Hiker"]), ("Big Club", ["Big Club", "Big Club"])):
|
||||
title, desc, body, _, _, _ = self.page(name, credits)
|
||||
head = self.head(body)
|
||||
self.assertIn(f'<p class="page-head__lede">{name} is credited with ', head)
|
||||
self.assertNotIn('id="about-author"', str(body))
|
||||
text = re.sub(r"<[^>]+>", " ", str(body))
|
||||
self.assertIsNone(PRONOUN.search(re.sub(r"In brief\..*", "", text, flags=re.S)), name)
|
||||
self.assertIsNone(PRONOUN.search(title + " " + desc), name)
|
||||
|
||||
def test_an_organisation_shows_nothing_about_itself_and_is_not_a_person(self):
|
||||
_, desc, body, _, _, jsonld = self.page("Big Club", ["Big Club"])
|
||||
html = str(body)
|
||||
self.assertNotIn("checker would refuse", html + desc)
|
||||
self.assertNotIn("a long way", html)
|
||||
self.assertIsNone(jsonld)
|
||||
|
||||
def test_each_kind(self):
|
||||
recs, root, by, gs = self.fixture(["Jo Walker", "Ann and Bo", "Big Club", "Nobody Listed"])
|
||||
self.assertEqual({n: g["kind"] for n, g in by.items()},
|
||||
{"Jo Walker": "person", "Ann and Bo": "people", "Big Club": "organisation", "Nobody Listed": ""})
|
||||
self.assertEqual([n for n, g in by.items() if authors.is_human(g)], ["Ann and Bo", "Jo Walker"])
|
||||
_, _, body, _, _, jsonld = authors.author_page(by["Ann and Bo"], recs, SITE, gs)
|
||||
self.assertIn('<p class="kicker">Route authors</p><h1>Ann and Bo</h1>', str(body))
|
||||
self.assertIn("Ann and Bo are a couple", str(body))
|
||||
self.assertIsNone(jsonld) # a pair is not one Person
|
||||
self.assertIsNone(authors.author_page(by["Nobody Listed"], recs, SITE, gs)[5])
|
||||
|
||||
def test_a_person_s_json_ld_carries_the_summary_and_own_site(self):
|
||||
_, _, _, _, _, node = self.page("Jo Walker", ["Jo Walker"])
|
||||
self.assertEqual(node["@type"], "Person")
|
||||
self.assertEqual(node["name"], "Jo Walker")
|
||||
self.assertEqual(node["description"], "Jo Walker is a hiker who works out long desert routes.")
|
||||
self.assertEqual(node["url"], "https://jowalker.example/")
|
||||
self.assertEqual(node["sameAs"], ["https://jowalker.example/"])
|
||||
_, _, _, _, _, bare = self.page("Sam Hill", ["Jo Walker and Sam Hill"])
|
||||
self.assertNotIn("description", bare)
|
||||
|
||||
def test_only_people_lead_the_index(self):
|
||||
credits = ["Jo Walker"] * 3 + ["Ann and Bo"] * 3 + ["Big Club"] * 4 + ["Nobody Listed"] * 5 + ["Sam Hill and Jo Walker"]
|
||||
recs = self.routes(credits)
|
||||
root = self.fixture_root()
|
||||
gs = authors.author_pages(recs, root)
|
||||
self.assertEqual([g["name"] for g in authors.prominent(gs)], ["Ann and Bo", "Jo Walker"])
|
||||
html = str(authors.index_page(recs, SITE, root)[2])
|
||||
lead = html[:html.index('class="browse-about"')]
|
||||
self.assertIn('<div class="results__lead"><h2 class="results__group"><a href="/authors/jo-walker/">Jo Walker</a>', lead)
|
||||
self.assertIn('<p class="results__intro">Jo Walker is a hiker who works out long desert routes.</p>', lead)
|
||||
self.assertIn('/authors/ann-and-bo/">Ann and Bo</a>', lead)
|
||||
for name in ("big-club", "nobody-listed"):
|
||||
self.assertNotIn(f'class="results__group"><a href="/authors/{name}/"', lead)
|
||||
self.assertIn(f'/authors/{name}/', html)
|
||||
rest = html[html.index('class="author-list"'):]
|
||||
self.assertGreater(rest.index("/authors/big-club/"), rest.index("/authors/nobody-listed/")) # organisations last
|
||||
self.assertNotIn("checker would refuse", html)
|
||||
self.assertNotIn("<table", html)
|
||||
|
||||
class RecentTest(unittest.TestCase):
|
||||
def rec(self, i, added, changes=()):
|
||||
r = fake(i)
|
||||
@@ -382,6 +550,23 @@ class SummaryTest(unittest.TestCase):
|
||||
self.assertIn("The longest is", text)
|
||||
self.assertLess(text.index("Namet2"), text.index("Namet1"))
|
||||
|
||||
def test_the_routes_and_authors_clause_can_be_left_out(self):
|
||||
recs = [fake(i, km=mi(100 * i)) for i in (1, 2, 3)]
|
||||
for r in recs:
|
||||
r["name"] = f"Name{r['id']}"
|
||||
r["derived"] = {**r.get("derived", {}), "kind": "route"}
|
||||
r["route"] = {"creator": "A" if r["id"] == "t1" else "B"}
|
||||
self.assertIn("routes by 2 authors", str(summary.facts(recs, recs)))
|
||||
self.assertNotIn("routes by", str(summary.facts(recs, recs, by_authors=False)))
|
||||
self.assertNotIn("are routes", str(summary.facts(recs, recs, by_authors=False)))
|
||||
|
||||
def test_a_publisher_with_two_pages_is_named_once_with_numbered_links(self):
|
||||
html = authors.source_links([
|
||||
{"publisher": "The Trek", "url": "https://a/1"}, {"publisher": "Gear", "url": "https://g"},
|
||||
{"publisher": "The Trek", "url": "https://a/2"}])
|
||||
self.assertEqual(html, ['The Trek (<a href="https://a/1">1</a>, <a href="https://a/2">2</a>)',
|
||||
'<a href="https://g">Gear</a>'])
|
||||
|
||||
def test_a_small_place_gets_a_paragraph_for_each_trail(self):
|
||||
recs = [fake(1, hike={"summary": "First sentence. Second sentence here.", "high_point_m": 2000, "high_point": "Top"})]
|
||||
text = str(summary.details(recs))
|
||||
|
||||
Reference in new issue
Block a user