From 298f1b9fd9d9b80b355c246928046b433c4abccb Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Tue, 17 Nov 2026 06:40:16 -0700 Subject: [PATCH] Give every page of trails one layout, with the map beside the rows, and set no tables Every page that shows a set of trails (home, places, lists, Routes, authors, Triple Crown, rankings, newest) has the same layout: the trails as rows with their map beside them from 900 px wide up, and a short map band above the rows when narrower. The home page gets its headline back on the contour ground, with the ten lists as one line of links. A trail page has its actions in its head and the map in a fixed frame beside At a glance. No page sets a table: every set of trails is the standard trail row, and other sets are rows in the same language. Route authors' names link to their pages from route rows and trail pages, the Routes page says how many routes by how many authors, and the Lists index has a Route authors entry. No trail's facts changed. Co-Authored-By: Claude Fable 5.2 --- CHANGELOG.md | 11 ++ web/assets/app.js | 12 ++ web/assets/map/outdoor.json | 2 +- web/assets/style.css | 323 ++++++++++++++++++++++----------- web/olt/authors.py | 65 +++---- web/olt/browse.py | 7 +- web/olt/common.py | 2 +- web/olt/home.py | 144 +++++++++++---- web/olt/layout.py | 4 + web/olt/leftout.py | 38 ++-- web/olt/pagekit.py | 101 ++++++++--- web/olt/pages.py | 11 +- web/olt/placefacets.py | 4 +- web/olt/regions.py | 69 +++---- web/olt/standing.py | 117 +++++------- web/olt/summary.py | 43 ++--- web/olt/trail.py | 132 ++++++++------ web/olt/views.py | 12 +- web/tests/test_extra.py | 46 ++++- web/tests/test_first_screen.py | 129 +++++++++---- web/tests/test_hike.py | 6 +- web/tests/test_length_facts.py | 6 +- web/tests/test_outdoor_map.py | 8 +- web/tests/test_pages.py | 21 ++- web/tests/test_saved.py | 2 +- web/tests/test_search_text.py | 6 +- web/tests/test_trust.py | 28 +-- web/tests/test_views.py | 35 ++-- 28 files changed, 843 insertions(+), 541 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7079b7c..2bfe099 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## 2026-11-17 - Every page that shows trails has one layout, and the site sets no tables + +- Every page that shows a set of trails now has the same layout: the home page, every place page, every list, the Routes page, the route authors, the Triple Crown, the rankings and the newest trails. Under the page's name and its one line come the trails as rows, with their map beside them on the right. The map stays in view as the rows scroll. This holds from 900 px wide up, so at 1,187 px and at a tablet held sideways the map is beside the trails, not under them. On a narrower screen the map is a short band above the rows, a third of the screen high at most, never below the list. +- A map frame takes the shape of the ground it shows, between a little taller than wide and a little more than half as tall as wide, so the tracks fill it. The drawing in the page and the live map fit the same ground in the same frame, as before. +- Text about a set of trails now comes after the rows, under its own heading, and is one short paragraph: the longest and shortest, the loops and routes, the most common terrain and the highest point on file. The quickest and slowest to walk, the designations, a place's share of the trails and which place has the most are gone. A list's explanation of how it is picked is there too. +- The home page opens with its headline and one sentence on the contour ground of the old hero, at a fraction of its height. The ten lists are one quiet line of links under it, ending in "All lists". The search, Filters and Clear are over the rows. Open, the filters lie over the rows instead of pushing the page down, and "Show the trails", Escape or a click outside closes them. The Places page's links to the parts of the country are the same kind of line. +- A trail page now has its actions in its head: the GPX, the trail's own site and Save stand at the right, over the At a glance panel, on a wide screen, and in one row under the name on a phone. Directly under the head are the map and At a glance, tops level. The map frame is the same calm landscape on every trail page, 3 by 2 (4 by 3 on a phone), with the track fitted inside it. Under the map are the summary, the "In brief" paragraph and "Last checked" in small print. Under At a glance are the downloads and the map's credit, which used to fill the caption under the map. On a phone a strip of the length, time and states comes before the map. +- At a glance sets the length larger. A built length or a whole-system figure is a line of its own across the panel. A trail name too long for two lines is set a step smaller. +- No page sets a table. The National Scenic Trails and National Recreation Trails lists lost their tables of figures and are lists like the others. The Triple Crown is its three trails as rows with their map, each row adding its high point, climb and year designated. The rankings are the trails as rows in rank order, each led by its rank and its figure. The route authors with the most routes lead `/authors/` with their routes as rows, and an author's page shows their routes as rows with their guides. The trails considered and left out, the newest changes, the places on `/numbers/`, and the tables on the About, data, schema, sources and method pages are rows in the same language: a name, a sentence and a line of short facts. Every field of a record, at the foot of its page, is a list of fields and values. +- No trail's facts changed. + ## 2026-11-16 - Fifteen more main tracks re-cut to one walk - The rule that a trail's length is one end-to-end walk, with one branch at a split, was applied to the tracks built from OpenStreetMap. A scan of all of them looked for a main track that holds two different ways between the same two points, which is what a split looks like in the geometry, and found fifteen. Each of those tracks is now one walk. The other way is in `alternates.geojson`, or, where it was the same road mapped twice, left out. Lengths below are the measured track before and after, in miles (kilometres). No published length (`length_km`) changed, and each record has a history entry. diff --git a/web/assets/app.js b/web/assets/app.js index d3118ce..21bc630 100644 --- a/web/assets/app.js +++ b/web/assets/app.js @@ -1346,6 +1346,8 @@ 'time-asc': 'time-desc', 'time-desc': 'time-asc', 'climb-desc': 'climb-asc', 'climb-asc': 'climb-desc' }; /* The Saved page's list also has the order saved (rows numbered in data-order by section 1c). */ if (savedPage) SORT_KEYS.saved = 1; + /* A ranking (/numbers/) has its rank as an order (rows numbered in data-rank by the page). */ + if (document.querySelector('.entry[data-rank]')) SORT_KEYS.rank = 1; function normalizeSortKey(value, dflt) { if (SORT_KEYS[value]) return value; @@ -1363,6 +1365,7 @@ var bo = b.dataset.order ? Number(b.dataset.order) : Infinity; return cmpNum(ao, bo) || cmpStr(an, bn); } + if (key === 'rank') return cmpNum(Number(a.dataset.rank || Infinity), Number(b.dataset.rank || Infinity)); if (key === 'name') return cmpStr(an, bn); if (key === 'name-desc') return cmpStr(bn, an); if (key === 'climb-desc' || key === 'climb-asc') { @@ -1501,6 +1504,15 @@ if (toggle) toggle.setAttribute('aria-expanded', open ? 'true' : 'false'); } if (toggle) toggle.addEventListener('click', function () { showPanels(!panels.hasAttribute('data-open')); }); + /* The open panels lie over the rows: Show the trails, Escape, or a click outside the form closes them. */ + var done = form.querySelector('.filters__done'); + if (done) done.addEventListener('click', function () { showPanels(false); if (toggle) toggle.focus(); }); + form.addEventListener('keydown', function (e) { + if (e.key === 'Escape' && panels && panels.hasAttribute('data-open')) { showPanels(false); if (toggle) toggle.focus(); } + }); + document.addEventListener('click', function (e) { + if (panels && panels.hasAttribute('data-open') && !form.contains(e.target)) showPanels(false); + }); /* The count is the one live region. Keep it quiet through the first application below so nothing is announced on load, and write to it diff --git a/web/assets/map/outdoor.json b/web/assets/map/outdoor.json index 4103961..597cdfa 100644 --- a/web/assets/map/outdoor.json +++ b/web/assets/map/outdoor.json @@ -17,7 +17,7 @@ "tileSize": 512, "maxzoom": 12, "bounds": [-180, 14, -50, 85], - "attribution": "Relief: Terrain Tiles, USGS and others (full credit below the map)" + "attribution": "Relief: Terrain Tiles, USGS and others (full credit beside the map)" }, "olt-contours": {"type": "vector", "tiles": ["contours://{z}/{x}/{y}"], "minzoom": 11, "maxzoom": 15, "bounds": [-180, 14, -50, 85]} }, diff --git a/web/assets/style.css b/web/assets/style.css index 0922127..4a4197e 100644 --- a/web/assets/style.css +++ b/web/assets/style.css @@ -850,10 +850,10 @@ html.js .map__status:not([data-say]) { display: none; } .map__message > * + * { margin-block-start: var(--space-3); } .map__message h2 { font-size: var(--step-2); } -.mapfig--detail { --map-ratio: 1 / 1; } +.mapfig--detail { --map-ratio: 4 / 3; } @media (min-width: 48rem) { .mapfig { --map-ratio: 2 / 1; } - .mapfig--detail { --map-ratio: 4 / 3; } + .mapfig--detail { --map-ratio: 3 / 2; } } @media (max-width: 40rem) { :root { --collar: 1.25rem; } @@ -964,45 +964,75 @@ html.js .map__status:not([data-say]) { display: none; } .hero__counts { display: grid; gap: var(--space-3); margin-block-start: var(--space-3); } .hero__cta { padding: var(--space-3) var(--space-5); font-size: var(--step-1); } -/* Home: the trails first. The lists, a search bar, then the trails, with the overview map beside - them on a wide screen (it stays in view while the list scrolls). On a narrow screen the map - follows the list, and the bar has a link to it. */ -.home { - display: grid; - gap: var(--space-1) var(--space-6); - grid-template-columns: minmax(0, 1fr); - grid-template-areas: "lists" "bar" "results" "map" "notes"; - align-items: start; +/* Home: the introduction. The headline and its one sentence on the contour ground of the old hero, + at a fraction of its height, and the row of lists under a hairline. */ +.intro { position: relative; overflow: hidden; padding-block: var(--space-6) var(--space-4); } +.intro::before { + content: ""; + position: absolute; + inset-block: 0; + inset-inline: max(0px, (100% - var(--container)) / 2 - var(--gutter)); + background: url("contours.svg") 70% 30% / cover no-repeat; + -webkit-mask-image: radial-gradient(ellipse 60% 120% at 92% 0%, #000 0%, rgb(0 0 0 / 0.6) 30%, rgb(0 0 0 / 0.2) 60%, transparent 85%), linear-gradient(to right, #000 82%, transparent 100%); + mask-image: radial-gradient(ellipse 60% 120% at 92% 0%, #000 0%, rgb(0 0 0 / 0.6) 30%, rgb(0 0 0 / 0.2) 60%, transparent 85%), linear-gradient(to right, #000 82%, transparent 100%); + -webkit-mask-composite: source-in; + mask-composite: intersect; + pointer-events: none; } -.home__lists { grid-area: lists; min-inline-size: 0; } -.home__bar { grid-area: bar; min-inline-size: 0; } -.home__results { grid-area: results; min-inline-size: 0; } -.home__map { grid-area: map; min-inline-size: 0; scroll-margin-block-start: var(--space-4); } -.home__notes { grid-area: notes; } -.finder__notes { display: grid; gap: var(--space-2); } +.intro__inner { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); } +.intro h1 { max-inline-size: 30ch; font-size: var(--step-3); font-weight: 600; line-height: 1.12; letter-spacing: -0.015em; text-wrap: balance; } +.intro__lede { max-inline-size: 40rem; color: var(--ink-2); font-size: var(--step-1); line-height: 1.45; text-wrap: pretty; } +@media (max-width: 39.99rem) { + .intro { padding-block: var(--space-4) var(--space-3); } + .intro__lede { font-size: var(--step-0); } +} +.home { padding-block: var(--space-4) var(--space-7); } +.finder__notes { display: grid; gap: var(--space-2); margin-block-start: var(--space-6); } .results { container: results / inline-size; } -@media (min-width: 64rem) { - .home { - grid-template-columns: minmax(0, 1fr) 27rem; - grid-template-areas: "lists lists" "bar map" "results map" "notes ."; - } - .home__map { position: sticky; inset-block-start: var(--space-4); } - .home__map .map { aspect-ratio: auto; block-size: clamp(20rem, calc(100dvh - 17rem), 46rem); } - .filters__maplink { display: none; } - .home .results-head { padding-block-end: var(--space-2); } +.home__bar { margin-block-end: var(--space-3); } + +/* Every page that shows a set of trails: the rows, with their map. Wide: the rows on the left, the + map on the right, where it stays in view as the rows scroll. Narrow: the map is a short band above + the rows. The frame takes the shape of the ground it shows (--map-ratio, written on the figure), + no taller than the window allows. Text about the set follows the rows (.browse-about). */ +.browse { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); align-items: start; } +.browse__list, .browse__map { min-inline-size: 0; } +/* The height follows from the column's width and the frame's shape (--frame-n, width over height), + capped by the window; set as a height, not a ratio, so a cap never narrows the frame. */ +.browse__map { container-type: inline-size; scroll-margin-block-start: var(--space-4); } +.browse__map .map { + aspect-ratio: auto; + block-size: clamp(10rem, calc((100cqi - 2 * var(--collar)) / var(--frame-n, 1.5)), 34svh); } -@media (min-width: 64rem) and (pointer: fine) { - .home .results-sort .select { min-block-size: 2.25rem; } - .home .lists-row .chips a { min-block-size: 2rem; } +.browse__map .mapfig__caption { padding-block-start: var(--space-2); font-size: var(--step--2); } +.browse__map .mapfig__caption p { color: var(--ink-3); } +/* On a narrow screen the band keeps its legend; the sentences under it are for the wide layout (and + for screen readers, which still have them). */ +@media (max-width: 55.99rem) { + .browse__map .mapfig__caption p { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } + .browse__map .mapfig__caption { padding-block-start: var(--space-1); } +} +@media (min-width: 56rem) { + .browse { grid-template-columns: minmax(0, 1fr) minmax(20rem, 0.85fr); grid-template-areas: "list map"; gap: var(--space-6); } + .browse__list { grid-area: list; } + .browse__map { grid-area: map; position: sticky; inset-block-start: var(--space-4); } + .browse__map .map { block-size: clamp(16rem, calc((100cqi - 2 * var(--collar)) / var(--frame-n, 1.5)), calc(100svh - 12rem)); } + .browse--no-map { grid-template-columns: minmax(0, 1fr); grid-template-areas: "list"; } + .browse--no-map .browse__list { max-inline-size: 48rem; } +} +@media (min-width: 56rem) and (pointer: fine) { + .browse .results-sort .select { min-block-size: 2.25rem; } .home .filters__bar .input, .home .filters__bar .button { min-block-size: 2.5rem; } } -/* Beside the map the rows are a little closer, so more of the list is in view. */ -@media (min-width: 64rem) { - .home .entry { padding-block: 0.5rem; } -} +.browse--no-map .note { margin-block-start: var(--space-5); max-inline-size: var(--measure); color: var(--ink-2); font: 400 var(--step--1)/1.5 var(--font-sans); } +.browse-about { margin-block-start: var(--space-7); padding-block-start: var(--space-4); border-block-start: 1px solid var(--ink); } +.browse-about > h2 { margin-block-end: var(--space-3); font-size: var(--step-2); } +.browse-about .prose { line-height: 1.55; } +.browse-about .prose > h2 { margin-block-start: var(--space-5); font-size: var(--step-1); } +.browse-about .prose > p { text-wrap: pretty; } -/* The search bar: the search field, a Filters control that opens the panels, Clear (shown only - when something is set), and on a narrow screen a link to the map. */ +/* The search bar: the search field, a Filters control that opens the panels, and Clear (shown only + when something is set). */ .filters__bar { display: flex; align-items: stretch; gap: var(--space-2); } .filters__search { flex: 1 1 auto; min-inline-size: 0; } .filters__bar .button { flex: none; min-block-size: 2.75rem; } @@ -1012,8 +1042,22 @@ html.js .map__status:not([data-say]) { display: none; } .filters__clear[hidden] { display: none; } /* The panels: the existing filter fields, in columns where there is room. With JavaScript they open from the bar; without it the bar and panels are not offered at all (see below). */ +.filters { position: relative; } .filters__panels { margin-block-start: var(--space-2); border: 1px solid var(--ink); background: var(--surface); } html.js .filters__panels:not([data-open]) { display: none; } +/* Open, the panels lie over the rows below the bar, as a sheet laid on the table: the page does not + move, and the map beside them shows what the filters leave. */ +html.js .filters__panels { + position: absolute; + z-index: 30; + inset-inline: 0; + inset-block-start: 100%; + max-block-size: min(72svh, 46rem); + overflow-y: auto; + overscroll-behavior: contain; + box-shadow: 6px 6px 0 var(--rule); +} +.filters__end { position: sticky; inset-block-end: 0; display: flex; justify-content: flex-end; padding: var(--space-3) var(--space-4); border-block-start: 1px solid var(--rule); background: var(--surface); } .filters__panel > summary { display: none; } .filters__more > summary { display: flex; @@ -1434,48 +1478,58 @@ html:not(.js) .list-head__arrow { display: none; } .titleblock--with-plate .titleblock__text > :first-child { grid-column: 2; grid-row: 1; align-self: center; } } -/* Trail page body. The first screen holds the map and the key facts: a short lead and the - buttons, then the map, in the left column; At a glance (and the downloads under it) in the - right one, level with the top of the left. On a narrow screen the order is the buttons, the - facts, the map, the elevation profile and the downloads. The aside is often taller than the - viewport, so it scrolls with the page rather than sticking. */ +/* Trail page body. Directly under the head: the map, the dominant thing, with At a glance beside it, + tops level. Under the map the reading column (the summary and "In brief"); under At a glance the + downloads and the credit. Then, across the page, the elevation profile. The map frame is a calm + landscape of the same shape on every trail page, the track fitted inside it; never taller than + the window. On a narrow screen: a strip of the key facts, the map, the facts, the words, the + downloads, the profile. */ .detail { display: grid; - gap: var(--space-4) var(--space-6); + gap: var(--space-5) var(--space-6); grid-template-columns: minmax(0, 1fr); - grid-template-areas: "lead" "glance" "map" "aside"; + grid-template-areas: "strip" "map" "glance" "text" "aside" "profile"; align-items: start; - padding-block-start: var(--space-3); + padding-block-start: var(--space-4); } -.detail--with-profile { grid-template-areas: "lead" "glance" "map" "profile" "aside"; } -.detail__lead { grid-area: lead; display: grid; gap: var(--space-3); min-inline-size: 0; } -.detail__lead:not(:has(*)) { display: none; } +.trail-strip { grid-area: strip; } +.detail__map { grid-area: map; min-inline-size: 0; } .detail__side { display: contents; } .detail__glance { grid-area: glance; min-inline-size: 0; } -.detail__map { grid-area: map; min-inline-size: 0; } -.detail__profile { grid-area: profile; min-inline-size: 0; } -.detail__main { min-inline-size: 0; } .detail__aside { grid-area: aside; min-inline-size: 0; } .detail__aside > * + * { margin-block-start: var(--space-5); } +.detail__text { grid-area: text; min-inline-size: 0; } +.detail__profile { grid-area: profile; min-inline-size: 0; } +.detail__main { min-inline-size: 0; } +/* With no track the frame holds a notice: as tall as the notice needs, and never less than a calm frame. */ +.detail .map--empty { min-block-size: 18rem; } +@media (min-width: 64rem) { .detail .map--empty { min-block-size: 26rem; } } @media (min-width: 64rem) { .detail { grid-template-columns: minmax(0, 1fr) 22rem; - grid-template-rows: auto 1fr; - grid-template-areas: "lead side" "map side"; + grid-template-rows: auto 1fr auto; + grid-template-areas: "map side" "text side" "profile profile"; + row-gap: var(--space-6); } - .detail--with-profile { grid-template-rows: auto 1fr auto; grid-template-areas: "lead side" "map side" "profile profile"; } - .detail__lead:not(:has(*)) { display: block; } + .trail-strip { display: none; } .detail__side { display: grid; grid-area: side; gap: var(--space-5); align-content: start; min-inline-size: 0; } .detail__side > * { grid-area: auto; } - /* The map is as tall as the window allows, and stays in view while the facts and downloads - beside it scroll past. */ - .detail__map { align-self: start; position: sticky; inset-block-start: var(--space-4); } - .detail__map .map { aspect-ratio: auto; block-size: clamp(30rem, calc(100dvh - 15rem), 52rem); } - /* With no track there is no map: the notice keeps its own height. */ - .detail--no-map .detail__map { position: static; } - .detail--no-map .detail__map .map { block-size: auto; min-block-size: 22rem; } } +/* The key facts in one line on a phone: length, time and where. */ +.trail-strip { + display: flex; + flex-wrap: wrap; + gap: var(--space-1) var(--space-5); + padding-block: var(--space-2); + border-block: 1px solid var(--ink); + font: 400 var(--step--1)/1.35 var(--font-sans); +} +.trail-strip dt { color: var(--ink-2); font: 600 var(--step--2)/1.3 var(--font-sans); letter-spacing: 0.08em; text-transform: uppercase; } +.trail-strip dd { margin: 0; font-weight: 500; } +.trail-strip div:first-child dd { font-weight: 600; } +@media (min-width: 64rem) { .trail-strip { display: none; } } + .block + .block { margin-block-start: var(--space-7); } .block > h2 { display: flex; @@ -1856,11 +1910,13 @@ td .linklist a { font-weight: 400; } .rawrecord[open] > summary::after { transform: translateY(25%) rotate(-135deg); } .rawrecord > summary:focus-visible { outline-offset: -5px; } .rawrecord > .note { padding: 0 var(--space-4) var(--space-3); } -.rawrecord .table-wrap { border: 0; border-block-start: 1px solid var(--rule); } -.rawrecord__table { table-layout: fixed; } -.rawrecord__table thead th:first-child { inline-size: 34%; } -.rawrecord__table th, .rawrecord__table td { overflow-wrap: anywhere; } -.rawrecord__table td { font-family: var(--font-mono); font-size: var(--step--1); } +/* Each field and its value: the field's name on the left, its value beside it, a hairline between. */ +.rawrecord__fields { margin: 0; border-block-start: 1px solid var(--rule); font: 400 var(--step--1)/1.45 var(--font-sans); } +.rawrecord__fields > div { display: grid; grid-template-columns: minmax(0, 34%) minmax(0, 1fr); gap: var(--space-1) var(--space-4); padding: var(--space-2) var(--space-4); border-block-end: 1px solid var(--rule); } +.rawrecord__fields > div:last-child { border-block-end: 0; } +.rawrecord__fields dt, .rawrecord__fields dd { margin: 0; overflow-wrap: anywhere; } +.rawrecord__fields dd { font-family: var(--font-mono); } +@media (max-width: 40rem) { .rawrecord__fields > div { grid-template-columns: minmax(0, 1fr); } } /* 404 page search */ .notfound-search { @@ -1880,7 +1936,9 @@ td .linklist a { font-weight: 400; } on the first screen (the map and the facts of a trail, the first trails of a list). */ .page-head { padding-block: var(--space-3) 0; } .page-head .titleblock { margin-block: var(--space-2) 0; gap: var(--space-2) var(--space-4); } -.page-head .titleblock h1 { font-size: var(--step-3); line-height: 1.1; } +.page-head .titleblock h1 { font-size: var(--step-3); line-height: 1.1; text-wrap: balance; } +/* A long name is set a step smaller, so it keeps to two or three lines. */ +.page-head .titleblock--long h1 { font-size: var(--step-2); line-height: 1.15; } .page-head .titleblock--with-plate { grid-template-columns: 4.5rem minmax(0, 1fr); } .page-head .titleblock .plate { padding: 0.35rem; } .page-head .titleblock__text { gap: var(--space-1); } @@ -1888,23 +1946,36 @@ td .linklist a { font-weight: 400; } @media (min-width: 48rem) { .page-head .titleblock--with-plate { grid-template-columns: 6rem minmax(0, 1fr); } } -/* The lead above the map: the first sentence of the summary, when it is short. The summary in - full is under the map. */ -.trail-lede { max-inline-size: 46rem; font-size: var(--step-0); line-height: 1.45; text-wrap: pretty; } -.trail-actions { margin-block-start: 0; } -/* On a phone the buttons come first. */ -@media (max-width: 47.99rem) { - .detail__lead { display: flex; flex-direction: column; } - .detail__lead .trail-actions { order: -1; } +/* The head of a trail page: the name on the left; the actions at the right on a wide screen, as wide + as the column of facts under them and level with the foot of the name; on a narrow one, a row + under the name. */ +.trail-head { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 var(--space-6); } +.trail-head > .breadcrumb { grid-column: 1 / -1; } +.trail-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-block-start: var(--space-3); } +.trail-actions .button { min-block-size: 2.5rem; } +@media (min-width: 64rem) { + .trail-head { grid-template-columns: minmax(0, 1fr) 22rem; align-items: end; } + .trail-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; margin-block-start: 0; } + .trail-actions .button { justify-content: center; } + .trail-actions__gpx { grid-column: 1 / -1; } } -/* Under the map: the summary in full, the generated "In brief" paragraph, the date of the last - check, and the other pages about the trail. */ -.trail-text { max-inline-size: 46rem; margin-block-end: var(--space-6); } -.trail-text > h2 { margin-block-end: var(--space-3); font-size: var(--step-2); } +@media (max-width: 39.99rem) { + .trail-actions { flex-wrap: nowrap; } + .trail-actions .button { flex: 0 1 auto; min-inline-size: 0; padding-inline: var(--space-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } + .trail-actions .trail-actions__gpx { flex: 1 1 auto; } +} +/* Under the map: the summary in full, the "In brief" paragraph, the date of the last check (small + print), and the other pages about the trail. */ +.trail-text { max-inline-size: 42rem; } .trail-summary { font-size: var(--step-1); line-height: 1.5; text-wrap: pretty; } -.trail-brief { margin-block-start: var(--space-3); line-height: 1.55; text-wrap: pretty; } -.trail-checked { margin-block-start: var(--space-3); } -.trail-more .morelinks { max-inline-size: 46rem; margin-block-end: var(--space-6); } +.trail-brief { margin-block-start: var(--space-4); line-height: 1.6; text-wrap: pretty; } +.trail-checked { margin-block-start: var(--space-3); color: var(--ink-3); font: 400 var(--step--2)/1.4 var(--font-sans); letter-spacing: 0.02em; } +.detail__text .morelinks { max-inline-size: 42rem; margin-block-start: var(--space-6); } +/* The map's credit, small print under the downloads. */ +.map-credit { color: var(--ink-2); font: 400 var(--step--2)/1.5 var(--font-sans); } +.map-credit > * + * { margin-block-start: var(--space-2); } +.map-credit__title { color: var(--ink-2); font: 600 var(--step--2)/1.3 var(--font-sans); letter-spacing: 0.08em; text-transform: uppercase; } +.map-credit a { overflow-wrap: anywhere; } /* At a glance: the hiker's facts, a legend box like the panels */ .glance { border: 1px solid var(--ink); background: var(--surface); } @@ -1927,6 +1998,13 @@ td .linklist a { font-weight: 400; } .glance__facts > div:first-child, .glance__facts > div:nth-child(2):not(.glance__wide) { border-block-start: 0; } .glance__wide { grid-column: 1 / -1; } +.glance__facts > .glance__wide:first-child + div { border-block-start: 1px dotted var(--rule-strong); } +.glance__facts > .glance__wide:first-child + div:not(.glance__wide) + div:not(.glance__wide) { border-block-start: 1px dotted var(--rule-strong); } +/* The length leads, large; a built or whole-system figure is one quiet line each under it. */ +.glance__length { --len-size: var(--step-3); } +.glance__length .len--stack { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--space-2); } +.glance dd .glance__aside { display: block; margin-block-start: var(--space-1); } +.glance__length small { margin-block-start: var(--space-2); } .glance dt { color: var(--ink-2); font: 600 var(--step--2)/1.3 var(--font-sans); @@ -2099,21 +2177,31 @@ td .linklist a { font-weight: 400; } .hero--short { padding-block: var(--space-3) var(--space-2); } .hero--short .hero__inner { gap: var(--space-1); } -/* The home page's lists: a short row. The label leads it, and the pills fit one row or two on a - wide screen; on a phone they are one row that scrolls sideways within itself. */ -.lists-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); } -.lists-row__title { font: 600 var(--step--2)/1.3 var(--font-sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); } -.lists-row .chips { flex: 1 1 0; min-inline-size: 0; } -@media (min-width: 40rem) and (pointer: fine) { .lists-row .chips a { min-block-size: 2.25rem; } } +/* The home page's lists: one quiet line of links under the headline, each with its count, ending in + All lists. On a phone it is one line that scrolls sideways within itself. */ +.lists-row { margin-block-start: var(--space-2); padding-block-start: var(--space-3); border-block-start: 1px solid var(--rule); } +/* Each link carries its dot in its own left padding, and the line is pulled left by that padding and + clipped, so a link that starts a line shows no dot (as the facts line of a row does). */ +.lists-row ul { + display: flex; flex-wrap: wrap; align-items: center; + margin-inline-start: -0.8em; clip-path: inset(0 0 0 0.8em); + padding: 0; list-style: none; font: 500 0.8rem/1.3 var(--font-sans); +} +.lists-row li { position: relative; display: inline-flex; align-items: center; padding-inline-start: 0.8em; } +.lists-row li::before { content: "\00B7"; position: absolute; inset-inline-start: 0.26em; color: var(--ink-3); } +.lists-row a { display: inline-flex; align-items: center; min-block-size: 2rem; color: var(--ink); text-decoration-color: var(--rule-strong); } +.lists-row a:hover { text-decoration-color: var(--trail); } +.lists-row__n { display: inline-block; margin-inline-start: 0.35em; color: var(--ink-2); font-variant-numeric: tabular-nums; } +.lists-row__all a { color: var(--link); font-weight: 600; } @media (max-width: 39.99rem) { - .lists-row { display: grid; gap: var(--space-1); } - .lists-row .chips { - flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; - margin-inline: calc(-1 * var(--gutter)); padding: 3px var(--gutter); + .lists-row ul { + flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; clip-path: none; + margin-inline: calc(-1 * var(--gutter)); padding-inline: calc(var(--gutter) - 0.8em) var(--gutter); } - /* The row scrolls by touch; a scrollbar under it reads as a stray white band */ - .lists-row .chips::-webkit-scrollbar { display: none; } - .lists-row .chips li { flex: none; } + .lists-row li:first-child::before { visibility: hidden; } + .lists-row ul::-webkit-scrollbar { display: none; } + .lists-row li { flex: none; } + .lists-row a { min-block-size: 2.75rem; } } .section--finder { padding-block-start: var(--space-4); } .pills { display: flex; flex-wrap: wrap; gap: var(--space-2); } @@ -2159,21 +2247,6 @@ a.tag:hover { background: var(--sunken); } .page-head .chips { margin-block-start: var(--space-2); } .place > * + * { margin-block-start: var(--space-6); } .section.place { padding-block-start: var(--space-4); } -/* A place, list or routes page: the list, then the map, then the page's own text; on a wide - screen the list beside the text and the map, which stays in view as the list scrolls. */ -.place-grid { - display: grid; align-items: start; gap: var(--space-5) var(--space-6); - grid-template-columns: minmax(0, 1fr); grid-template-areas: "list" "map" "text"; -} -.place-grid__text { grid-area: text; min-inline-size: 0; } -.place-grid__list { grid-area: list; min-inline-size: 0; } -.place-grid__map { grid-area: map; min-inline-size: 0; } -@media (min-width: 64rem) { - .place-grid { grid-template-columns: minmax(0, 1fr) 27rem; grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "list text" "list map"; gap: var(--space-4) var(--space-6); } - .place-grid__map { position: sticky; inset-block-start: var(--space-4); } - .place-grid__map .map { aspect-ratio: auto; block-size: clamp(18rem, calc(100dvh - 17rem), 40rem); } -} - /* About hub */ .about-hub__list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr)); gap: 0 var(--space-5); max-inline-size: none; } .about-hub__list li, .about-hub__list li:first-child { padding-block: var(--space-2); border-block-start: 0; border-block-end: 1px dotted var(--rule-strong); } @@ -2232,6 +2305,11 @@ a.tag:hover { background: var(--sunken); } .entry__facts .line__status { display: inline; font: inherit; } .entry__guides { grid-column: 2 / -1; grid-template-columns: minmax(0, 1fr); } } +/* A figure that leads a row's facts (a ranking's figure, with its rank) is set as the length is; the + facts a page adds for comparing a few trails keep their labels. */ +.entry__rank { color: var(--trail); font-weight: 600; font-variant-numeric: tabular-nums; } +.entry__figure { font-weight: 600; } +.entry__more dt { position: static !important; inline-size: auto !important; block-size: auto !important; overflow: visible !important; clip-path: none !important; margin-inline-end: 0.35em; color: var(--ink-2); font: inherit; letter-spacing: 0; text-transform: none; } /* A wider card has room for a larger logo. */ @container results (min-width: 34rem) and (max-width: 65.99rem) { .entry { --plate-w: 6rem; gap: var(--space-2) var(--space-4); } @@ -2325,3 +2403,30 @@ html:not(.js) .saved-body { display: none; } .shelf--author { grid-template-rows: auto 1fr auto; padding: var(--space-4); } .shelf--author .shelf__items, .shelf--author .shelf__more { display: block; } } + +/* 14. Rows of things that are not trails ------------------------------------ */ + +/* Files, terms, changes, places and the trails left out are set as a trail's row is, with no emblem: + a name, its sentence, a line of short facts and small print (olt/pagekit.py plain_entry). */ +.entries .entry--plain { grid-template-columns: minmax(0, 1fr); grid-template-areas: "body"; padding: var(--space-3) 0; } +.entry--plain .entry__name { font-size: var(--step-0); } +.entry--plain .entry__desc { display: block; -webkit-line-clamp: none; line-clamp: none; overflow: visible; max-inline-size: var(--measure); font-size: var(--step--1); } +.entry__meta { + display: flex; flex-wrap: wrap; align-items: baseline; + margin-inline-start: -1.1em; clip-path: inset(0 0 0 1.1em); + color: var(--ink); font: 400 var(--step--1)/1.5 var(--font-sans); +} +.entry__meta > span { position: relative; padding-inline-start: 1.1em; } +.entry__meta > span::before { content: "\00B7"; position: absolute; inset-inline-start: 0.4em; color: var(--ink-2); } +.entry__meta > span:first-child { font-weight: 600; } +.entry__label { color: var(--ink-2); font-weight: 400; } +.entry__small { color: var(--ink-3); font: 400 var(--step--2)/1.45 var(--font-sans); letter-spacing: 0.02em; } +.entry__small a { color: var(--link); } +.prose .entries--plain { margin-block-start: var(--space-3); } +.results__n { color: var(--ink-2); font: 500 var(--step--1)/1 var(--font-sans); } +.results__group a { color: var(--ink); text-decoration-color: var(--rule-strong); } +.results--short .entries { margin-block-start: var(--space-3); } +.numbers > section + section, .left-out > section + section { margin-block-start: var(--space-7); } +.numbers > section > h2 { margin-block-end: var(--space-3); font-size: var(--step-2); } +.numbers > section > ul { padding-inline-start: 1.2em; } +.left-out > section { margin-block-start: var(--space-7); } diff --git a/web/olt/authors.py b/web/olt/authors.py index 3ae6ebe..cfebd2a 100644 --- a/web/olt/authors.py +++ b/web/olt/authors.py @@ -152,33 +152,27 @@ def index_page(records, site, repo_root): top = prominent(gs) rest = [g for g in gs if g not in top] 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. " - f"Every author has a page of their own, 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)}") - sections = "" - if top: - blocks = "\n".join(_block(g) for g in top) - sections += (f'

Authors with {PROMINENT_MIN} or more routes

\n' - f'

{_plural(len(top), "author")}, the most routes first.

\n' - f'\n') + lede = f"{len(routes)} long hiking routes, worked out by {len(gs)} authors, each with a page of their own." + lede_more = (f"

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)}

") + # 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'{esc(g["name"])} {_plural(len(g["routes"]), "route")}', + g["routes"], regions.route_guides) for g in top] + rest_html = "" if rest: items = "\n".join(f'
  • {esc(g["name"])}, {_route_links(g)}
  • ' for g in rest) heading = "Other authors" if top else "All authors" - sections += f'

    {heading}

    \n\n' - rows = [] - for g in gs: - first = True - for r in g["routes"]: - rows.append([Markup(f'{esc(g["name"])}') if first else "", pagekit.trail_link(r), year_text(r), - words.length(r["length_km"], mi=r["derived"]["length_mi"]), facets.GPX_STATUS[facets.gpx(r)], guide_text(r)]) - first = False + rest_html = f'\n' + listing = home.results(groups=groups, routes_list=True, top=2) if top else "" + about = (f"

    {_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.

    ") body = (pagekit.head("Route authors", lede, [("Trails", "/"), ("Lists", "/lists/"), ("Routes", "/routes/")]) + f"""
    - {sections} -

    Every route, with its author

    - {pagekit.table(["Author", "Route", "Year", "Length", "GPX", "Published in"], rows, caption="Routes by author")} -

    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.

    +

    Authors with {PROMINENT_MIN} or more routes

    + {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}
    """) @@ -205,16 +199,6 @@ def author_page(g, records, site, all_pages): sites = own_sites(g) if sites: lede += " Their own page: " + "; ".join(f'{esc(h)}' for h, u in sites) + "." - show_credit = any(r["route"].get("creator") != g["name"] for r in routes) - rows = [] - for r in routes: - cells = [pagekit.trail_link(r), words.length(r["length_km"], mi=r["derived"]["length_mi"]), - trail.place_text(r).removeprefix("in "), hike.days(r) or "Not on file", guide_text(r)] - if show_credit: - credit = r["route"].get("creator", "") - cells.append(esc(credit) if credit != g["name"] else "") - rows.append(cells) - heads = ["Route", "Length", "Where it runs", "Usual time", "Published in"] + (["Credited as"] if show_credit else []) shared = [r for r in routes if g["others"].get(r["id"])] shared_note = "" if shared: @@ -223,21 +207,18 @@ def author_page(g, records, site, all_pages): for r in shared: people = [f'{esc(o)}' 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 = '

    ' + " ".join(lines) + "

    " - briefs = "".join(f'

    {esc(common.plain_name(r))}

    \n{trail.brief(r)}\n' for r in routes) + shared_note = "

    " + " ".join(lines) + "

    " + briefs = "".join(f'

    {esc(common.plain_name(r))}

    \n{trail.brief(r)}\n' for r in routes) nav_items = [x for x in prominent(all_pages) if x is not g] nav = (f'") if nav_items else "" - more = (f'
    {summary.facts(routes, records)}
    ' if n >= 3 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}

    {'About the route' if n == 1 else 'About each route'}

    {briefs}" body = (pagekit.head(f"Routes by {g['name']}", lede, [("Trails", "/"), ("Lists", "/lists/"), ("Authors", INDEX)]) + f"""
    -

    {'The route' if n == 1 else 'The routes'}

    - {pagekit.table(heads, rows, caption=f"Routes by {g['name']}")} - {shared_note} -

    {'About the route' if n == 1 else 'About each route'}

    - {briefs} - {more} - {home.overview_map(routes, f"Map of the routes by {g['name']}")} +

    {'The route' if n == 1 else 'The routes'}

    + {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']}")} {nav}
    """) diff --git a/web/olt/browse.py b/web/olt/browse.py index cb50125..c8e08e3 100644 --- a/web/olt/browse.py +++ b/web/olt/browse.py @@ -52,9 +52,6 @@ class List: # (list's trails, all trails) -> a plain sentence or two that says what the list covers # where that is not every trail: how many have the fact the list is built on. note: Optional[Callable] = None - # The page opens with a table of key figures for its trails (olt/standing.py): for a short - # list of named standing, where a reader compares the trails. - table: bool = False # A larger least size than MIN_SIZE, where the list is thin by nature (a month's list). min_size: int = 0 @@ -154,11 +151,11 @@ HALF_MI = 500 LISTS = ( List("national-scenic-trails", "National Scenic Trails", "The long trails the United States Congress has named National Scenic Trails.", - facets.is_national, page_title="National Scenic Trails: {n} Long Hiking Trails", group="standing", table=True), + facets.is_national, page_title="National Scenic Trails: {n} Long Hiking Trails", group="standing"), List("national-recreation-trails", "National Recreation Trails", "Trails whose designation says they are National Recreation Trails.", _designation(r"National Recreation Trail"), - page_title="National Recreation Trails: {n} Long Hiking Trails", group="standing", table=True), + page_title="National Recreation Trails: {n} Long Hiking Trails", group="standing"), List("routes", "Routes", facets.ROUTE_DEFINITION, lambda r: facets.kind(r) == "route", page_title="Long Hiking Routes by Author: {n} Routes", group="standing", noun="Long Hiking Routes"), diff --git a/web/olt/common.py b/web/olt/common.py index 8aff1b4..4a7ac9f 100644 --- a/web/olt/common.py +++ b/web/olt/common.py @@ -295,7 +295,7 @@ TRAIL_MAP_CREDIT = Markup(f"Base map: {BASE_MAP_CREDIT} Relief and contours: {es FOOTER_MAP_CREDIT = Markup( f"Base maps: {BASE_MAP_CREDIT} Elevation, relief and contours: Terrain Tiles, with data courtesy of " "the U.S. Geological Survey, NOAA, ArcticDEM and INEGI; Canada terrain data under the Open Government " - "Licence - Canada. The full credit is under each trail map.") + "Licence - Canada. The full credit is beside each trail map.") def save_button(rec, *, row=True): """The control that saves a trail to the visitor's saved trails, or takes it off. diff --git a/web/olt/home.py b/web/olt/home.py index 1c4019f..99661fa 100644 --- a/web/olt/home.py +++ b/web/olt/home.py @@ -130,7 +130,27 @@ def gpx_cell(rec): EAGER_ROWS = 4 -def entry(rec, *, level=3, extra="", routes_list=False, hidden=False, eager=False): +# {credit: [(author name, page path)]} for the authors who have a page (olt/authors.py link_map), +# set by pages.render_site: a route's "Route by" line links each named author who has one. +AUTHOR_LINKS = {} + + +def use_authors(links): + AUTHOR_LINKS.clear() + AUTHOR_LINKS.update(links or {}) + + +def route_by_html(rec): + """facets.route_by(rec) as HTML, each author's name in it a link to their page.""" + text = str(esc(facets.route_by(rec))) + for name, href in AUTHOR_LINKS.get(facets.author(rec), []): + n = str(esc(name)) + if n in text: + text = text.replace(n, f'{n}', 1) + return Markup(text) + + +def entry(rec, *, level=3, extra="", routes_list=False, hidden=False, eager=False, lead=None, rank=None, more=()): """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. @@ -138,6 +158,10 @@ def entry(rec, *, level=3, extra="", routes_list=False, hidden=False, eager=Fals row's Route badge and "Route by" line would repeat; both are left out there. hidden: written hidden, for app.js to show (the Saved page). eager: the logo is not lazy-loaded (a row of the first screen). + lead: (label, HTML) of a figure that leads the line of facts, set as the length is (a ranked + 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). 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 @@ -167,7 +191,7 @@ 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

    {tag_html}

    ' if tag_html else "" - by = f'\n

    {esc(facets.route_by(rec))}

    ' if route and not routes_list else "" + by = f'\n

    {route_by_html(rec)}

    ' if route and not routes_list else "" desc = entry_desc(rec) desc_html = f'\n

    {esc(desc)}

    ' if desc else "" time_html = esc(facets.time_text(rec)) + (' estimate' if est else "") @@ -175,6 +199,14 @@ def entry(rec, *, level=3, extra="", routes_list=False, hidden=False, eager=Fals f'computed') if climb_m is not None else "" if hidden: attrs += " hidden" + lead_html = "" + if rank is not None: + attrs += f' data-rank="{rank}"' + if lead: + no = f'No. {rank} ' if rank is not None else "" + lead_html = (f'\n
    {esc(lead[0])}
    {no}' + f'{lead[1]}
    ') + more_html = "".join(f'\n
    {esc(label)}
    {value}
    ' for label, value in more) return f"""
  • {common.plate(rec, eager=eager)}
    {kicker} @@ -182,10 +214,10 @@ def entry(rec, *, level=3, extra="", routes_list=False, hidden=False, eager=Fals {common.save_button(rec)}{by}{desc_html}

    {where_html(rec)}

    -
    +
    {lead_html}
    Length
    {words.length(rec["length_km"], "stack", rec["derived"]["length_mi"])}
    Time
    {time_html}
    -
    GPX
    {gpx_cell(rec)}
    {climb_html} +
    GPX
    {gpx_cell(rec)}
    {climb_html}{more_html}
    {extra}
  • """ @@ -316,7 +348,6 @@ def finder_form(records, c=None, steps=None): - Map
    @@ -331,6 +362,7 @@ def finder_form(records, c=None, steps=None): {"".join(more)}
    +

    """ @@ -391,7 +423,7 @@ def list_head(sort_key="name"): SAVED_ORDER = ("saved", "Order saved") -def sort_select(default_sort="name", saved=False): +def sort_select(default_sort="name", saved=False, ranked=""): """The one sort control of every list of trails, with the page's default order selected. Hidden without JavaScript (style.css): it cannot work then, and the HTML is already in the default order. @@ -400,6 +432,9 @@ def sort_select(default_sort="name", saved=False): if saved: sorts = (SAVED_ORDER,) + tuple(sorts) default_sort = SAVED_ORDER[0] + elif ranked: + sorts = (("rank", f"Rank: {ranked}"),) + tuple(sorts) + default_sort = "rank" else: default_sort = facets.normalize_sort(default_sort) options = "".join( @@ -424,7 +459,8 @@ def key(official=True): """ -def results(recs=None, *, finder=False, groups=None, routes_list=False, default_sort="name", saved=False, top=3): +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): """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 @@ -446,11 +482,17 @@ def results(recs=None, *, finder=False, groups=None, routes_list=False, default_ A list that holds every trail (the finder's, the Saved page's) is marked data-every-trail: there app.js knows every trail id, and drops the saved ids that match no trail. + + ranked: the label of a ranking (a /numbers/ page): the rows keep the order given, each + numbered, and "Rank" is the list's first order. lead(rec) -> (label, HTML) or None: a figure + that leads each row's line of facts (the ranked figure, or one a page compares). more(rec) -> + [(label, HTML)]: further facts for each row (entry()). tools: False for a short list inside a + page that has its own (no count and no sort control). """ default_sort = facets.normalize_sort(default_sort) if groups is None: groups = [(None, recs, None)] - groups = [(heading, facets.sort_records(list(items), default_sort), extra_fn) + groups = [(heading, list(items) if ranked else facets.sort_records(list(items), default_sort), extra_fn) for heading, items, extra_fn in groups] total = sum(len(g[1]) for g in groups) shown = [r for g in groups for r in g[1]] @@ -463,7 +505,9 @@ def results(recs=None, *, finder=False, groups=None, routes_list=False, default_ level = top + 1 if heading else top rows = "\n".join(entry(r, level=level, extra=extra_fn(r) if extra_fn else "", routes_list=routes_list, hidden=saved, - eager=not saved and seen + i < EAGER_ROWS) for i, r in enumerate(items)) + 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)) seen += len(items) if heading: lists += f'\n {heading}' @@ -483,8 +527,10 @@ def results(recs=None, *, finder=False, groups=None, routes_list=False, default_ else: count = f'

    {total} {noun}

    ' empty = "" - tools = sort_select(default_sort, saved=saved) - dflt = SAVED_ORDER[0] if saved else default_sort + if not tools: + return Markup(f'
    {lists}
    ') + tools = sort_select(default_sort, saved=saved, ranked=ranked) + dflt = SAVED_ORDER[0] if saved else "rank" if ranked else default_sort return Markup(f"""
    {count} @@ -576,6 +622,9 @@ def overview_map(recs, label, *, wide=False, scope="", saved=False): fr = sketch.frame(box) frame_attr = f' data-frame="{",".join(f"{v:g}" for v in fr)}"' drawing = sketch.svg(sketch.overview_features(ids), fr, ident=True) + # The frame takes the shape of the ground it shows, within calm bounds, so the tracks fill it + # (style.css .browse__map); the drawing and the live map fit the same ground either way. + frame_attr += f' style="--frame-n: {frame_ratio(fr):.3f}"' return Markup(f"""
    @@ -595,15 +644,40 @@ def overview_map(recs, label, *, wide=False, scope="", saved=False):
    """) -def place_grid(text_html, listing, map_html): - """The body of a place, list or routes page: the list beside its map on a wide screen, with the - page's own text above the map there, so that the first trails are on the first screen. On a - narrow screen the list comes first, then the map, then the text (style.css .place-grid).""" - return f"""
    -
    {text_html}
    -
    {listing}
    -
    {map_html}
    +# The shape of a browsing page's map frame: the ground's own width over height, held between these. +RATIO_MIN, RATIO_MAX = 0.8, 1.6 + + +def frame_ratio(fr): + """Width over height of the frame `fr` (Web Mercator), between RATIO_MIN and RATIO_MAX.""" + plane = sketch.Plane(fr) + return max(RATIO_MIN, min(RATIO_MAX, plane.w / plane.h if plane.h else RATIO_MAX)) + + +def browse_view(listing, map_html, *, about="", about_title="", about_id="about-these"): + """The body of every page that shows a set of trails: the rows, with their map. + + On a wide screen the rows are on the left and the map on the right, where it stays in view as the + rows scroll; on a narrow one the map is a short band above the rows. Text about the set (about, + HTML) follows the rows as a section of its own under about_title. A set too small to map (the + map is a note) is the rows alone, with the note under them (style.css .browse).""" + has_map = 'class="mapfig' in str(map_html) + if has_map: + grid = f"""
    +
    {map_html}
    +
    {listing}
    """ + else: + grid = f"""
    +
    {listing}{map_html}
    +
    """ + if about: + grid += f""" +
    +

    {esc(about_title or "About these trails")}

    +
    {about}
    +
    """ + return Markup(grid) def has_overview_map(recs, scope=""): @@ -613,19 +687,19 @@ def has_overview_map(recs, scope=""): def lists_row(records, picks=()): - """The row of lists on the home page: the lists the data file marks for it (picks, from - datafiles.home_lists: key and position), in that order, each with its count, then "All lists". - A marked list that is not shown today (too few trails, or nearly all of them) is left out.""" + """The row of lists under the home page's headline: the lists the data file marks for it (picks, + from datafiles.home_lists: key and position), in that order, each with its count, then "All + lists". A marked list that is not shown today (too few trails, or nearly all of them) is left out.""" have = {lst.key: (lst, recs) for lst, recs in browse.shown(records)} items = "".join( - f'
  • {esc(have[key][0].title)} ' - f'{len(have[key][1])}
  • ' + f'
  • {esc(have[key][0].title)}' + f'{len(have[key][1])}
  • ' for key in picks if key in have) if not items: return "" return f"""""" @@ -656,19 +730,19 @@ def render(records, site, repo_root=""): f'Report a problem or ' f'suggest a trail.

    ') picks = home_picks(datafiles.lists(repo_root)) - return f"""
    -
    -

    {esc(site.tagline.rstrip("."))}

    -

    {lede}

    + listing = f"""
    {finder_form(records, c, length_steps(records))}
    + {results(recs, finder=True)}""" + return f"""
    +
    +

    {esc(site.tagline.rstrip("."))}

    +

    {lede}

    + {lists_row(records, picks)}
    -
    {lists_row(records, picks)}

    Every trail

    -
    {finder_form(records, c, length_steps(records))}
    -
    {results(recs, finder=True)}
    -
    {overview_map(records, "Map of the trails the filters leave", wide=True, scope="all")}
    -
    + {browse_view(listing, overview_map(records, "Map of the trails the filters leave", scope="all"))} +

    Not for navigation: tracks vary in quality and some trails are unfinished. Check each trail’s own maps before you go.

    {contribute}
    diff --git a/web/olt/layout.py b/web/olt/layout.py index 1c08287..ae24544 100644 --- a/web/olt/layout.py +++ b/web/olt/layout.py @@ -230,6 +230,10 @@ def layout(title, body, *, path, description="", maps=False, outdoor=False, scri leaves it out of the sitemap. """ site = site or site_settings.load() + # The site sets no tables: one written in Markdown or by hand is set as rows (olt/pagekit.py). + if "{esc(e.get('note', ''))}

    " + # In the language of a trail's row: the name as a row's name, "once listed here" as a tag + # where a route's tag is, where and how long as its line of facts, the deciding sentence + # as its text, the date and the source as small print. + tag = 'Once listed here' if e.get("was_listed") else "" + text = [esc(e.get("note", ""))] if e.get("waiting_for"): - why += (f"

    It would be listed if this changes: " - f"{esc(e['waiting_for'])}

    ") - source = "" + text.append(f"It would be listed if this changes: {esc(e['waiting_for'])}") + small = [f'Decided '] if e.get("source_url"): - source = (f'Source page') - rows += ( - f'{esc(e.get("name", ""))}{mark}' - f'{esc(_where(e))}' - f'{_length(e)}' - f'{why}' - f'" - f'{source}') - groups += f"""
    + small.append(f'Source page') + items.append(pagekit.plain_entry(esc(e.get("name", "")), tag=tag, text=text, + facts=[esc(_where(e)), _length(e)], small=small)) + groups += f"""

    {esc(heading)}

    {esc(meaning)}

    -
    - - {rows}
    TrailWhereLengthWhy it is left outDecidedSource
    + {pagekit.plain_list(items)}
    """ body = f"""
    {bread}
  • Considered and left out
  • Considered and left out

    Trails and routes that were looked at for this dataset and left out, and why.

    -
    +

    {_opening(entries, site)}

    {groups}
    """ diff --git a/web/olt/pagekit.py b/web/olt/pagekit.py index 89ca9a7..0f3e8f2 100644 --- a/web/olt/pagekit.py +++ b/web/olt/pagekit.py @@ -1,4 +1,6 @@ -"""Small pieces the new view pages share: a page heading with a breadcrumb, a table, a ranked row.""" +"""Small pieces the view pages share: a page heading with a breadcrumb, and rows of things that are not trails.""" +import re + from . import words from .markup import Markup, esc @@ -16,36 +18,81 @@ def head(h1, lede_html, crumbs, *, kicker=""):
    """ -# A table with at least this many columns is set as one block per row on a phone (style.css). -STACK_COLUMNS = 4 +# The site sets no tables. A set of things (files, terms, changes, places) is shown as rows in the +# language of a trail's row: a name, a sentence where there is one, and a line of short facts. + +# A cell longer than this (in characters of text) is a sentence of the row, not a fact in its line. +LONG_CELL = 60 + + +def _text_len(html): + return len(re.sub(r"<[^>]+>", "", str(html)).strip()) + + +def plain_entry(name_html, *, text=(), facts=(), small=(), tag="", level=3, heading=True): + """One row of something that is not a trail: name_html as a row's name, `tag` (HTML) above it as a + route tag is, `text` (HTML paragraphs) as a row's sentence, `facts` (HTML) on a line as a row's + facts are, `small` (HTML) as small print.""" + kicker = f'

    {tag}

    ' if tag else "" + h = f"h{level}" if heading else "p" + paras = "".join(f'

    {t}

    ' for t in text if str(t).strip()) + line = "".join(f'{f}' for f in facts if str(f).strip()) + line = f'' if line else "" + fine = " · ".join(str(x) for x in small if str(x).strip()) + fine = f'

    {fine}

    ' if fine else "" + return (f'
  • {kicker}' + f'<{h} class="entry__name">{name_html}{paras}{line}{fine}
  • ') + + +def plain_list(items_html, label=""): + aria = f' aria-label="{esc(label)}"' if label else "" + return Markup(f'
      {"".join(items_html)}
    ') + + +def rows_list(headers, rows, caption=""): + """A set of things as rows: the first cell of each is its name; a long cell is its sentence; the + short ones are its line of facts, each with its column's title.""" + items = [] + for row in rows: + cells = [v if isinstance(v, Markup) else esc(v) for v in row] + text, facts = [], [] + for label, cell in zip(headers[1:], cells[1:]): + if not _text_len(cell): + continue + if _text_len(cell) > LONG_CELL: + text.append(cell) + else: + facts.append(f' {cell}') + items.append(plain_entry(cells[0], text=text, facts=facts, heading=False)) + return plain_list(items, caption) def table(headers, rows, *, caption="", numeric=(), row_heads=False, compare=False): - """A table in the site's table wrapper. headers: column titles; rows: lists of HTML cells - (Markup, or text that is escaped); numeric: column numbers set at the end of the cell; - row_heads: the first cell of each row is a row heading. + """A set of things, shown as rows (rows_list): headers are the titles of the cells, rows lists of + HTML cells (Markup, or text that is escaped). The other arguments are kept for the callers.""" + return rows_list(headers, rows, caption) - Every cell carries its label (data-label: its column's title, or in a compare table its row's - heading) so that a phone can set the same markup as blocks, with no sideways scrolling - (style.css): one block per row where the table has STACK_COLUMNS columns or more, and - compare: a table of figures down the side and one trail in each column, with a fixed layout - of equal columns, and on a phone one block per trail, headed by the trail's name.""" - def cell(i, value, label, head=False): - text = value if isinstance(value, Markup) else esc(value) - cls = ' class="num"' if i in numeric else "" - if head: - return f'{text}' - return f'{text}' - cap = f'{esc(caption)}' if caption else "" - num = ' class="num"' - head = "".join(f'{esc(h)}' for i, h in enumerate(headers)) - body = "".join( - "" + "".join(cell(i, v, row[0] if compare else headers[i], head=row_heads and i == 0) - for i, v in enumerate(row)) + "" - for row in rows) - mode = "columns" if compare else "rows" if len(headers) >= STACK_COLUMNS else "" - stack = f' data-stack="{mode}"' if mode else "" - return Markup(f'
    {cap}{head}{body}
    ') + +_TABLE = re.compile(r'(?:
    \s*)?]*>(.*?)(?:\s*
    )?', re.S) +_ROW = re.compile(r"]*>(.*?)", re.S) +_CELL = re.compile(r"<(th|td)\b[^>]*>(.*?)", re.S) +_CAPTION = re.compile(r"]*>(.*?)", re.S) + + +def untable(html): + """html with every table in it set as rows (rows_list). For the pages written from Markdown and by + hand, whose tables are plain: one head row, then body rows.""" + def one(m): + inner = m.group(1) + cap = _CAPTION.search(inner) + rows = [[c[1].strip() for c in _CELL.findall(r)] for r in _ROW.findall(inner)] + rows = [r for r in rows if r] + if not rows: + return "" + head, body = rows[0], rows[1:] + caption = re.sub(r"<[^>]+>", "", cap.group(1)) if cap else "" + return str(rows_list(head, [[Markup(c) for c in r] for r in body], caption)) + return _TABLE.sub(one, str(html)) def trail_link(rec): diff --git a/web/olt/pages.py b/web/olt/pages.py index 1926612..d7945b0 100644 --- a/web/olt/pages.py +++ b/web/olt/pages.py @@ -92,6 +92,7 @@ def render_site(records, out_dir, repo_root, site=None): dates = {} # page path -> its own date (YYYY-MM-DD), for the sitemap everything = seo.newest(records) author_links = authors.link_map(records, repo_root) + home.use_authors(author_links) for rec in records: # Read by common.name() wherever a page shows the record's name as text. rec["derived"]["name_lang"] = site.name_lang.get(rec["id"], "") @@ -161,7 +162,7 @@ def render_site(records, out_dir, repo_root, site=None): """Hold a view page built as (title, description, body, recs...) and note it for /lists/.""" t, d, b = built[:3] recs = built[3] if len(built) > 3 and isinstance(built[3], list) else None - pending.append((path, t, d, b, {"recs": recs})) + pending.append((path, t, d, b, {"recs": recs, "maps": 'data-map="overview"' in str(b)})) view_paths.append(path) layout.UNDER_LISTS.add(path) # its header item is Lists labels[path] = link_label @@ -172,7 +173,7 @@ def render_site(records, out_dir, repo_root, site=None): built = standing.collection_page(c, records, site) if built: view(standing.collection_path(c), "tables", f"{c['name']} trails compared", - f"The {c['name']} trails side by side: length, states, time, high point, climb and season.", built) + f"The {c['name']} trails with their map: length, time, high point, climb and the year each was named.", built) ranked = [] for spec in standing.RANKINGS: built = standing.ranking_page(spec, records, site) @@ -188,7 +189,7 @@ def render_site(records, out_dir, repo_root, site=None): authors_built = any(facets.kind(r) == "route" for r in records) if authors_built: t, d, b, routes = authors.index_page(records, site, repo_root) - view(authors.INDEX, "tables", "Route authors", f"The {len(routes)} routes by who published them, and where.", + view(authors.INDEX, "standing", "Route authors", f"The {len(routes)} routes by who published them, and where.", (t, d, b, routes)) for g in author_groups: t, d, b, needs_map, routes, person = authors.author_page(g, records, site, author_groups) @@ -225,7 +226,6 @@ def render_site(records, out_dir, repo_root, site=None): if lst.key == "routes": continue # /routes/ below, built whether or not the list is shown path = browse.path(lst) - before = standing.figures_section(recs) if lst.table else "" same = [(o, len(r)) for o, r in shown if o.group == lst.group and o.key != lst.key] after = "" if same: @@ -234,12 +234,13 @@ def render_site(records, out_dir, repo_root, site=None): f'{esc(o.title)} ({n})' for o, n in same) + "") after += placefacets.places_nav(lst, facet_plan) after += reference.terms_nav(path, repo_root) - t, d, b, needs_map = regions.list_page(lst, recs, len(records), site, records=records, before=before, after=after) + t, d, b, needs_map = regions.list_page(lst, recs, len(records), site, records=records, after=after) list_paths.append(path) add(path, t, d, b, maps=needs_map, recs=recs) t, d, b = regions.lists_index_page(records, site, extras) add("/lists/", t, d, b) t, d, b, needs_map = regions.routes_page(records, site, repo_root, after=reference.terms_nav("/routes/", repo_root), + n_authors=len(author_groups) if authors_built else None, author_pages=({c: authors.credit_html(c, links) for c, links in author_links.items()} if authors_built else None)) add("/routes/", t, d, b, maps=needs_map, recs=[r for r in records if facets.kind(r) == "route"]) diff --git a/web/olt/placefacets.py b/web/olt/placefacets.py index ad94872..0e8ef41 100644 --- a/web/olt/placefacets.py +++ b/web/olt/placefacets.py @@ -105,8 +105,8 @@ def page(p, records, site, all_pages):
    - {home.place_grid(f'
    {summary.facts(recs, records)}
    ', home.results(recs, default_sort=lst.sort, top=2), - home.overview_map(recs, f"Map of the trails in {name}: {lst.title}"))} + {home.browse_view(home.results(recs, default_sort=lst.sort, top=2), home.overview_map(recs, f"Map of the trails in {name}: {lst.title}"), + about=summary.facts(recs, records), about_title=f"About these trails in {name}")} {nav}
    """ diff --git a/web/olt/regions.py b/web/olt/regions.py index e4f2c32..8ac50c6 100644 --- a/web/olt/regions.py +++ b/web/olt/regions.py @@ -83,7 +83,7 @@ def regions_index_page(records, site): if not infos: continue recs = group_records(records, g) - jump.append(f'
  • {esc(name)} {len(recs)}
  • ') + jump.append(f'
  • {esc(name)}{len(recs)}
  • ') rows = "".join( f'
  • {esc(i["name"])}' f'{_plural(len(i["records"]))}
  • ' @@ -96,7 +96,7 @@ def regions_index_page(records, site): """ if across: links = ", ".join(f'{common.name(r)}' for r in across) - jump.append(f'
  • {facets.ACROSS_CANADA_NAME} {len(across)}
  • ') + jump.append(f'
  • {facets.ACROSS_CANADA_NAME}{len(across)}
  • ') blocks += f"""

    {facets.ACROSS_CANADA_NAME}

    {_plural(len(across))} that {"crosses" if len(across) == 1 else "cross"} the whole country rather than one province: {links}. @@ -109,34 +109,13 @@ def regions_index_page(records, site):

    The {len(records)} trails by state and province, grouped into parts of the United States ({n_us}) and Canada ({n_ca}). A trail that crosses several states is on each one’s page.

    -
      {"".join(jump)}
    +
    {blocks}
    """ description = (f"Where the {len(records)} long trails and routes are: {n_us} in the United States and {n_ca} in Canada, " f"by state and province, with the number in each.") return "Long Trails by State and Province: US and Canada", common.cut_at_word(description, common.DESCRIPTION_LIMIT), Markup(body) -def place_note(info, by_slug, records): - """A paragraph (HTML) on how the place stands among the others: its share of the trails, and which place - in its part of the country has the most.""" - n, total = len(info["records"]), len(records) - parts = [f"{esc(info['name'])} has {_plural(n, 'trail')} of the {total} trails on this site, " - f"{n / total * 100:.1f} percent of them."] - group = info["group"] - if group: - mates = [i for i in by_slug.values() if i["group"] == group] - top = max(mates, key=lambda i: (len(i["records"]), i["name"])) - gname = facets.GROUP_NAME[group] - if len(mates) > 1: - if top is info: - parts.append(f"Of the {len(mates)} places in {esc(gname)} with trails here, it has the most.") - else: - parts.append(f"Of the {len(mates)} places in {esc(gname)} with trails here, " - f'{esc(top["name"])} has the most, ' - f"{len(top['records'])}.") - return Markup("

    " + " ".join(parts) + "

    ") - - def region_page(slug, records, site, facet_pages=()): """(title, description, body, needs_map) for /regions//: the trails in one state or province. @@ -167,7 +146,6 @@ def region_page(slug, records, site, facet_pages=()): nav += (f'") - standing_note = place_note(info, by_slug, records) body = f"""
    @@ -178,8 +156,9 @@ def region_page(slug, records, site, facet_pages=()):
    - {home.place_grid(f'
    {summary.facts(recs, records)}{standing_note}{summary.details(recs)}
    ', - home.results(recs, top=2), home.overview_map(recs, f"Map of the trails in {info['name']}"))} + {home.browse_view(home.results(recs, top=2), home.overview_map(recs, f"Map of the trails in {info['name']}"), + about=f"{summary.facts(recs, records)}{summary.details(recs)}", + about_title=f"About the trails in {info['name']}")} {nav}
    """ name = info["name"] @@ -224,7 +203,7 @@ def route_guides(rec): f'
      {items}
    ') -def routes_page(records, site, repo_root=None, after="", author_pages=None): +def routes_page(records, site, repo_root=None, after="", author_pages=None, n_authors=None): """(title, description, body, needs_map) for /routes/: the Routes list.""" routes = [r for r in records if facets.kind(r) == "route"] by_author = collections.defaultdict(list) @@ -235,22 +214,23 @@ def routes_page(records, site, repo_root=None, after="", author_pages=None): groups = [(f"By {author_pages[a]}" if a in author_pages else f"By {esc(a)}", sorted(by_author[a], key=home.sort_name), route_guides) for a in sorted(by_author, key=str.lower)] n_gpx = _gpx_count(routes) - intro = f"""
    -

    Every other trail on this site is an official trail. Being a route says who looks after it, not + intro = f"""

    Every other trail on this site is an official trail. Being a route says who looks after it, not how rough it is: some routes are on maintained trail all the way, and some official trails have long road walks. The Walking line on each trail’s page says what the walking is.

    -

    {_plural(len(routes), "route")}, by {len(by_author)} authors. {n_gpx} {"has" if n_gpx == 1 else "have"} a GPX here; for the rest, +

    {_plural(len(routes), "route")}, by {n_authors or len(by_author)} authors. {n_gpx} {"has" if n_gpx == 1 else "have"} a GPX here; for the rest, each route’s page says whether its author gives the track away, sells it, or does not publish it. - Narrow them with the filters.

    -
    """ + Narrow them with the filters.

    """ + head_count = (f'\n

    {_plural(len(routes), "route")} by {_plural(n_authors, "author")}

    ' + if n_authors else "") body = f"""

    A list

    Routes

    -

    {esc(facets.ROUTE_DEFINITION)}

    +

    {esc(facets.ROUTE_DEFINITION)}

    {head_count}
    -
    - {home.place_grid(intro, home.results(groups=groups, routes_list=True, top=2), home.overview_map(routes, "Map of the routes with a GPX here"))} +
    + {home.browse_view(home.results(groups=groups, routes_list=True, top=2), home.overview_map(routes, "Map of the routes with a GPX here"), + about=intro, about_title="About routes")} {after}
    """ @@ -260,11 +240,12 @@ def routes_page(records, site, repo_root=None, after="", author_pages=None): Markup(body), home.has_overview_map(routes)) -def list_page(lst, recs, total, site, *, records=None, before="", after=""): +def list_page(lst, recs, total, site, *, records=None, before="", after="", lead=None): """(title, description, body, needs_map) for /lists//. - records: every trail, for the summary and the note. before: HTML placed above the map (a table - of figures); after: HTML placed under the list (links to related lists, places and terms).""" + records: every trail, for the summary and the note. before: HTML added to the text about the + list, after the summary (what its figures mean); after: HTML placed under it (links to related + lists, places and terms). lead: a figure to lead each row's line of facts (home.results).""" n_gpx = _gpx_count(recs) rule = (f"Lists are picked out by rule from each trail’s facts, so they change as trails are added " f"or corrected. A list is shown when it has at least {browse.MIN_SIZE} trails and no more than " @@ -278,15 +259,15 @@ def list_page(lst, recs, total, site, *, records=None, before="", after=""):

    A list

    {esc(lst.title)}

    -

    {esc(lst.blurb)} {_plural(len(recs))}, {n_gpx} with a GPX here.{note}

    +

    {esc(lst.blurb)} {_plural(len(recs))}, {n_gpx} with a GPX here.

    - {before} - {home.place_grid(f'
    {about}
    ', home.results(recs, default_sort=lst.sort, top=2), - home.overview_map(recs, f"Map of the trails in the list {lst.title}"))} + {home.browse_view(home.results(recs, default_sort=lst.sort, top=2, lead=lead), + home.overview_map(recs, f"Map of the trails in the list {lst.title}"), + about=f"{about}{before}{f'

    {esc(note.strip())}

    ' if note else ''}

    {rule}

    ", + about_title="About this list")} {after} -

    {rule}

    """ by_length = sorted(recs, key=lambda r: (r["length_km"], r["id"])) diff --git a/web/olt/standing.py b/web/olt/standing.py index a699f13..19b5f11 100644 --- a/web/olt/standing.py +++ b/web/olt/standing.py @@ -1,5 +1,5 @@ -"""Tables built from the records: key figures for a set of trails, a collection set side by side -(the Triple Crown), and the rankings under /numbers/. +"""Pages built from the records' figures: a collection with its map (the Triple Crown), and the +rankings under /numbers/, each as the site's trail rows. Nothing here names a trail. A collection is read from collections.toml; a ranking takes the records that carry the figure and says how many that is. Every figure comes from a record field, @@ -12,7 +12,6 @@ from . import browse, common, datafiles, elevation, facets, hike, pagekit, regio from .markup import Markup, esc NUMBERS = "/numbers/" -RANKING_ROWS = 25 # rows in a ranking table (the page says how many records have the figure) HUB_ROWS = 10 @@ -49,26 +48,8 @@ def season_cell(rec): return facets.season_text(rec) or "Not on file" -# One figure: (label, function of a record). The order is the order of columns and rows. -FIGURES = ( - ("Length", lambda r: words.length(r["length_km"], mi=r["derived"]["length_mi"])), - ("States and provinces", _places), - ("Typical time", time_cell), - ("High point", high_point_cell), - ("Climb", climb_cell), - ("Season", season_cell), - ("Publisher", lambda r: r.get("source", {}).get("publisher", "") or "Not on file"), -) - - -def key_figures_table(recs, caption="Key figures"): - """One row per trail: length, places, time, high point, climb, season and publisher.""" - rows = [[pagekit.trail_link(r)] + [fn(r) for _, fn in FIGURES] for r in recs] - return pagekit.table(["Trail"] + [label for label, _ in FIGURES], rows, caption=caption, row_heads=True) - - def figures_note(recs): - """What the figures in key_figures_table mean, with the caveats the records state.""" + """What the times and climbs of these trails mean, with the caveats the records state.""" est = sum(1 for r in recs if facets.time_days(r)[2]) parts = [f"Times that start with “About” are estimated from the length ({est} of these). " "Otherwise a source states the time.", @@ -84,11 +65,6 @@ def climb_caveat(recs): return ("Climb: " + text) if text else "" -def figures_section(recs, intro=""): - return (f'

    {intro}

    ' if intro else "") + str(key_figures_table(recs)) + \ - f'

    {esc(figures_note(recs))}

    ' - - # Collections ---------------------------------------------------------------------- def collection_members(collection, records): @@ -114,44 +90,41 @@ def collection_page(collection, records, site): total_mi = sum(r["derived"]["length_mi"] for r in recs) total_km = sum(r["length_km"] for r in recs) places = {c for r in recs for c in r.get("regions", [])} - lede = (f"{esc(collection['definition'])} Here are the {len(recs)} trails side by side, in the order the " - f"definition names them, from what each trail's page says. Their published lengths add up to {words.fmt_int(total_mi)} " - f"miles ({words.fmt_int(total_km)} km), across {len(places)} states and provinces.") - headers = ["Figure"] + [common.plain_name(r) for r in recs] - rows = [[label] + [fn(r) for r in recs] for label, fn in FIGURES] - rows.insert(0, ["Full name"] + [pagekit.trail_link(r) for r in recs]) - rows.append(["Designated"] + [common.designated_year(r) or "Not on file" for r in recs]) - source = (f'

    The award is described by {esc(collection.get("source_publisher", "its holder"))} at ' + lede = esc(collection['definition']) + totals = (f"

    Their published lengths add up to {words.fmt_int(total_mi)} miles ({words.fmt_int(total_km)} km), " + f"across {len(places)} states and provinces.

    ") + source = (f'

    The award is described by {esc(collection.get("source_publisher", "its holder"))} at ' f'{esc(collection["source_url"])}. ' f'{esc(figures_note(recs))} Lengths are the published figures. ' f'See the method for how they are checked.

    ') from . import home + + def more(r): + """The figures the trails are compared by, beyond a row's own: high point, climb, year named.""" + out = [] + hp_name, hp_m = high_point(r) + if hp_m is not None: + out.append(("High point", Markup(f"{esc(hp_name + ', ') if hp_name else ''}{words.elevation(hp_m)}"))) + climb = facets.row_climb_m(r) + if climb is not None: + out.append(("Climb", words.elevation(climb))) + year = common.designated_year(r) + if year: + out.append(("Designated", esc(str(year)))) + return out body = (pagekit.head(f"{name} trails compared", lede, [("Trails", "/"), ("Lists", "/lists/")]) + '
    ' - f'{pagekit.table(headers, rows, caption=f"The {name} trails side by side", row_heads=True, compare=True)}' - f'{source}' - f'
    {summary.facts(recs, records)}
    ' - f'{home.results(recs, top=2)}' + f'{home.browse_view(home.results(recs, top=2, ranked="", more=more, default_sort="name"), home.overview_map(recs, f"Map of the {name} trails"), about=f"{totals}{summary.facts(recs, records)}{source}", about_title=f"About the {name}")}' '
    ') desc = common.cut_at_word( - f"{name} trails side by side: published length, states, typical time, high point, climb and season for " - f"{abbrs}. Figures from each trail's page, not ranked.", common.DESCRIPTION_LIMIT) + f"The {name} trails, {abbrs}, with their map: published length, typical time, high point, climb and the year " + f"each was named. Figures from each trail's page, not ranked.", common.DESCRIPTION_LIMIT) return title, desc, Markup(body), recs # Numbers ---------------------------------------------------------------------------- -def _rank_rows(recs, value_of, cell_of, extra=None): - rows = [] - for i, r in enumerate(recs, 1): - row = [str(i), pagekit.trail_link(r), cell_of(r)] - if extra: - row.append(extra(r)) - rows.append(row) - return rows - - def _climb(rec): return facets.row_climb_m(rec) @@ -196,24 +169,19 @@ def ranking_page(spec, records, site): if len(have) < browse.MIN_SIZE: return None ranked = sorted(have, key=lambda r: (-value_of(r), r["id"])) - shown = ranked[:RANKING_ROWS] title = common.fit_title([f"{head}: {len(have)} Trails", head], site) if key == "highest-points": caveat = (f"{len(have)} of the {len(records)} trails have a high point stated in metres, as a source gives it. The rest " "give none, so they are not ranked.") else: caveat = _climb_coverage_note(records) + " " + climb_caveat(have) - rows = _rank_rows(shown, value_of, cell_of, extra=lambda r: words.length(r["length_km"], mi=r["derived"]["length_mi"])) - lede = (f"The {len(have)} trails and routes that have the figure, {how}. " - f"The table shows the first {len(shown)}. {esc(caveat)}") + lede = f"The {len(have)} trails and routes that have the figure, {how}." from . import home + notes = (f"

    {esc(caveat)}

    Where two trails share a figure, they are in name order. " + f"The same figures are on each trail’s page. See the method for what the caveats mean.

    ") body = (pagekit.head(head, lede, [("Trails", "/"), ("Lists", "/lists/"), ("By the numbers", NUMBERS)]) + '
    ' - f'{pagekit.table(["#", "Trail", label, "Length"], rows, caption=head, numeric=(0,))}' - f'

    Where two trails share a figure, they are in name order. ' - f'The same figures are on each trail’s page. See the method for what the caveats mean.

    ' - f'
    {summary.facts(have, records)}
    ' - f'{home.results(have, default_sort="climb-desc" if key != "highest-points" else "length-desc", top=2)}' + f'{home.browse_view(home.results(ranked, top=2, ranked=label, lead=lambda r: (label, cell_of(r))), home.overview_map(ranked, f"Map of the trails {how}"), about=f"{summary.facts(have, records)}{notes}", about_title="About this ranking")}' f'
    ') desc = common.cut_at_word(f"{len(have)} long hiking trails {how}, with the caveats that go with the figure.", @@ -235,31 +203,34 @@ def numbers_page(records, site, ranked_pages): longest = by_length[:HUB_ROWS] shortest = list(reversed(by_length[-HUB_ROWS:])) - def length_rows(rs): - return [[str(i), pagekit.trail_link(r), words.length(r["length_km"], mi=r["derived"]["length_mi"]), time_cell(r)] - for i, r in enumerate(rs, 1)] + def length_lead(r): + return ("Length", words.length(r["length_km"], mi=r["derived"]["length_mi"])) by_slug, _ = regions.collect_regions(records) - place_rows = [] + places = [] for slug in sorted(by_slug, key=lambda s: (-len(by_slug[s]["records"]), by_slug[s]["name"])): info = by_slug[slug] rs = info["records"] top = max(rs, key=lambda r: (r["length_km"], r["id"])) - place_rows.append([Markup(f'{esc(info["name"])}'), - str(len(rs)), str(sum(1 for r in rs if facets.kind(r) == "route")), - str(sum(1 for r in rs if facets.shape(r) == "loop")), - str(sum(1 for r in rs if facets.gpx_here(r))), - Markup(f'{pagekit.trail_link(top)}, {words.length(top["length_km"], mi=top["derived"]["length_mi"])}')]) + facts = [f'{len(rs)} trail{"" if len(rs) == 1 else "s"}'] + for n, word in ((sum(1 for r in rs if facets.kind(r) == "route"), "route"), + (sum(1 for r in rs if facets.shape(r) == "loop"), "loop")): + if n: + facts.append(f'{n} {word}{"" if n == 1 else "s"}') + facts.append(f'{sum(1 for r in rs if facets.gpx_here(r))} with a GPX') + places.append(pagekit.plain_entry( + f'{esc(info["name"])}', heading=False, facts=facts, + small=[Markup(f'Longest: {pagekit.trail_link(top)}, {words.length(top["length_km"], mi=top["derived"]["length_mi"])}')])) links = "".join(f'
  • {esc(head)} ({n} trails)
  • ' for path, head, n in ranked_pages) body = (pagekit.head("Long trails by the numbers", lede, [("Trails", "/"), ("Lists", "/lists/")]) - + f"""
    + + f"""

    Rankings

      {links}

    The {HUB_ROWS} longest by published length

    - {pagekit.table(["#", "Trail", "Length", "Typical time"], length_rows(longest), caption="The longest trails", numeric=(0,))}
    + {home.results(longest, top=3, ranked="length", lead=length_lead, tools=False)}

    The {HUB_ROWS} shortest by published length

    - {pagekit.table(["#", "Trail", "Length", "Typical time"], length_rows(shortest), caption="The shortest trails", numeric=(0,))}
    + {home.results(shortest, top=3, ranked="length", lead=length_lead, tools=False)}

    Trails by state and province

    A trail that crosses several states is counted in each, so the counts add up to more than {len(records)}.

    - {pagekit.table(["Place", "Trails", "Routes", "Loops", "With a GPX", "Longest"], place_rows, caption="Trails by state and province", numeric=(1, 2, 3, 4))}
    + {pagekit.plain_list(places, "Trails by state and province")}

    Lengths are the published figures, which are check values, not measured from a track. See the method. The longest trails and the shortest have their own lists.

    diff --git a/web/olt/summary.py b/web/olt/summary.py index e6e00bf..0426216 100644 --- a/web/olt/summary.py +++ b/web/olt/summary.py @@ -1,7 +1,7 @@ """A paragraph built from the records that a page lists: what the set holds. - facts(recs, records) count, longest and shortest, loops and routes, times, terrain, - holders, highest point, and how many have a GPX + facts(recs, records) one short paragraph: the longest and shortest, loops and routes, + the most common terrain and the highest point Every figure is counted from the records, and a sentence is left out when the records give it nothing to say. No trail is named here: the longest and the shortest are found @@ -57,51 +57,40 @@ def holder_counts(recs, records): def facts(recs, records): - """The summary paragraphs (Markup) for a set of trails. Empty for no trails.""" + """The summary of a set of trails: one short paragraph (Markup). Empty for no trails.""" if not recs: return Markup("") by_length = sorted(recs, key=lambda r: (r["length_km"], r["id"])) shortest, longest = by_length[0], by_length[-1] sentences = [] if len(recs) > 1: - sentences.append(f"The longest is {_name_link(longest)}, {_miles(longest)}. " - f"The shortest is {_name_link(shortest)}, {_miles(shortest)}.") + sentences.append(f"The longest is {_name_link(longest)}, {_miles(longest)}, " + f"and the shortest {_name_link(shortest)}, {_miles(shortest)}.") else: sentences.append(f"{_name_link(longest)} is {_miles(longest)} long.") loops = sum(1 for r in recs if facets.shape(r) == "loop") routes = [r for r in recs if facets.kind(r) == "route"] parts = [] if loops: - parts.append(_plural(loops, "loop")) + parts.append(f"{loops} {'is a loop' if loops == 1 else 'are loops'}") if routes: authors = {facets.author(r) for r in routes if facets.author(r)} - parts.append(f"{_plural(len(routes), 'route')}" + (f" by {_plural(len(authors), 'author')}" if authors else "")) + n = len(routes) + parts.append(f"{n} {'is a route' if n == 1 else 'are routes'}" + + (f" by {_plural(len(authors), 'author')}" if authors and n > 1 else "")) if parts and len(recs) > 1: - sentences.append(f"{_join(parts)[:1].upper()}{_join(parts)[1:]}.") - paragraphs = [" ".join(sentences)] - - more = [] - timed = sorted(recs, key=lambda r: facets.time_days(r)[:2]) - if len(recs) > 1: - quick, slow = timed[0], timed[-1] - more.append(f"The quickest to walk whole is {_name_link(quick)}, {facets.time_text(quick).lower()}, " - f"and the slowest is {_name_link(slow)}, {facets.time_text(slow).lower()}.") + text = _join(parts) + sentences.append(f"{text[:1].upper()}{text[1:]}.") terrain = terrain_counts(recs) - if terrain: + if terrain and len(recs) > 1: shown = _join( - f'{_list_link(records, "terrain-" + t, words.TERRAIN[t].lower(), n)}' for t, n in terrain[:4]) - have = sum(1 for r in recs if facets.terrain(r)) - more.append(f"Terrain is on file for {have} of them; the most common is {shown}.") - holders = holder_counts(recs, records) - if holders: - more.append("By designation: " + _join(_list_link(records, lst.key, lst.title, k) for lst, k in holders) + ".") + f'{_list_link(records, "terrain-" + t, words.TERRAIN[t].lower(), n)}' for t, n in terrain[:3]) + sentences.append(f"The most common terrain is {shown}.") high = [(hike.table(r).get("high_point_m"), r) for r in recs if isinstance(hike.table(r).get("high_point_m"), (int, float))] if high: m, top = max(high, key=lambda t: (t[0], t[1]["id"])) - more.append(f"The highest point stated is {words.elevation(m)}, on {_name_link(top)}.") - if more: - paragraphs.append(" ".join(more)) - return Markup("".join(f"

    {p}

    " for p in paragraphs)) + sentences.append(f"The highest point on file is {words.elevation(m)}, on {_name_link(top)}.") + return Markup(f"

    {' '.join(sentences)}

    ") DETAIL_MAX = 3 # a page with this many trails or fewer gets a paragraph on each, so it is not a bare list diff --git a/web/olt/trail.py b/web/olt/trail.py index e67a21c..ea707bc 100644 --- a/web/olt/trail.py +++ b/web/olt/trail.py @@ -128,6 +128,16 @@ def lead_line(rec): return rec.get("designation", "") +def credit_html(rec, credit, author_links=None): + """A route's credit as HTML, each author's name in it a link to their page (olt/authors.py link_map).""" + text = str(esc(credit)) + for name, href in (author_links or {}).get(facets.author(rec), []): + n = str(esc(name)) + if n in text: + text = text.replace(n, f'{n}', 1) + return Markup(text) + + def lead_html(rec, lead, author_links=None): """The lead line as HTML; on a route, the author's name in it links to the author's page (author_links: {credit: [(name, path)]} from olt/authors.py).""" @@ -384,6 +394,10 @@ def checked_line(rec): return Markup(f'

    Last checked

    ') +# A name longer than this (in characters) is set a step smaller in the page's head. +LONG_NAME = 48 + + def page_head(rec, author_links=None): route = common.is_route(rec) crumbs = ['
  • Places
  • '] @@ -408,10 +422,12 @@ def page_head(rec, author_links=None): kicker = f'

    {tag_html}

    ' if tag_html else "" lead = lead_line(rec) define = route_definition() if route else "" + # The actions belong to the head: on a wide screen they stand at its right, over the column of + # facts; on a narrow one they are one row under the name (style.css .trail-head). return f"""
    -
    +
    -
    +
    LONG_NAME else ""}"> {plate}
    {kicker} @@ -420,27 +436,18 @@ def page_head(rec, author_links=None): {define}
    + {action_buttons(rec)}
    """ -# The longest first sentence of the summary that stands above the map (about two lines beside the -# At a glance panel); a longer one is left to the "In brief" section below the map. -LEAD_MAX = 180 - - -def lead_text(rec): - """The line above the map: the first sentence of the summary, or "" when it is longer than LEAD_MAX - (the whole summary is under the map either way). Markup.""" - one = hike.one_line(rec) - if not one or len(one) > LEAD_MAX: - return "" - return Markup(f'

    {common.rich(one)}

    ') - - def action_buttons(rec): - """The buttons under the lead: the trail's own page, the GPX, Save.""" + """The trail's actions, in its head: the GPX (or where to get it), the trail's own page, Save.""" actions = [] + if rec["derived"].get("downloads"): + actions.append(f'{common.ICON_DOWNLOAD}Download the GPX') + else: + actions.append(f'GPX: {esc(facets.GPX_STATUS[facets.gpx(rec)])}') official = official_link(rec) if official: actions.append(f'{esc(official[1])} {common.ICON_EXTERNAL}') @@ -449,23 +456,30 @@ def action_buttons(rec): 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: - actions.append(f'GPX: {esc(facets.GPX_STATUS[facets.gpx(rec)])}') actions.append(str(common.save_button(rec, row=False))) - return f'

    {"".join(actions)}

    ' + return f'

    {"".join(actions)}

    ' + + +def strip(rec): + """The key facts in one tight line, for a phone: length, time and where (style.css shows it there + only; At a glance has the same facts in full).""" + codes = " ".join(esc(c.split("-")[-1]) for c in rec.get("regions", [])) + return f"""
    +
    {facets.LENGTH}
    {words.length(rec["length_km"], "inline", rec["derived"]["length_mi"])}
    +
    {facets.TIME}
    {esc(facets.time_text(rec))}
    +
    {facets.WHERE}
    {codes}
    +
    """ def trail_text(rec): - """The words under the map area: the summary in full, the "In brief" paragraph, the date of the - last check and the other pages about the trail. The text stays in the page for search engines.""" + """The words under the map: the summary in full, the "In brief" paragraph and the date of the + last check, then the other pages about the trail.""" summary = hike.summary(rec) lede = common.rich(summary) if summary else fallback_lede(rec) return f"""
    -

    In brief

    +

    In brief

    {lede}

    - {brief(rec, label=False)} + {brief(rec)} {checked_line(rec)}
    {links_panel(rec)}""" @@ -482,7 +496,8 @@ def shape_label(rec, records): def glance_row(label, value, note="", wide=False): note_html = f"{note if isinstance(note, Markup) else esc(note)}" if note else "" value_html = value if isinstance(value, Markup) else esc(value) - return Markup(f'
    {esc(label)}
    ' + cls = " glance__length" if label == facets.LENGTH else "" + return Markup(f'
    {esc(label)}
    ' f'
    {value_html}{note_html}
    ') @@ -507,9 +522,10 @@ def length_note(rec, records): def length_asides(rec, records): """What sits quietly under the length: the built figure of an unfinished trail, the holder's - larger figure with what it counts, then the link to the list the length puts the trail in.""" + larger figure with what it counts, then the link to the list the length puts the trail in. + Each is a line of its own.""" lines = [common.built_text(rec), common.system_text(rec), length_note(rec, records) or ""] - return Markup("
    ".join(str(line) for line in lines if line)) + return Markup("".join(f'{line}' for line in lines if line)) def time_note(rec, records): @@ -528,8 +544,10 @@ def glance(rec, records=None): records: every trail, so that terrain, shape, time and length link to the lists they put the trail in (left out when None).""" h = hike.table(rec) + # The length leads, set large. A built or a whole-system figure under it is a line across the + # whole panel, so the row is as wide as the panel. rows = [glance_row(facets.LENGTH, words.length(rec["length_km"], "stack", rec["derived"]["length_mi"]), - length_asides(rec, records))] + length_asides(rec, records), wide=bool(rec.get("built_km") or rec.get("system_km")))] rows.append(glance_row(facets.TIME, facets.time_text(rec), time_note(rec, records))) season = facets.season_text(rec) if season: @@ -590,10 +608,11 @@ def glance(rec, records=None): value = Markup(f'{esc(facets.GPX_STATUS[status])}') note = "" rows.append(glance_row(facets.GPX, value, note, wide=True)) - halves = [i for i, r in enumerate(rows) if 'class="glance__wide"' not in r] + halves = [i for i, r in enumerate(rows) if 'glance__wide' not in r.split(">", 1)[0]] if len(halves) % 2: # an odd one out takes the full width rather than leave a gap beside it i = halves[-1] - rows[i] = Markup(rows[i].replace("
    ", '
    ', 1)) + rows[i] = Markup(rows[i].replace("
    ", '
    ', 1) + .replace('
    ', '
    ', 1)) caution = "" if h.get("caution"): caution = f'

    Know before you go. {common.rich(common.sentence(h["caution"]))}

    ' @@ -653,11 +672,27 @@ def map_figure(rec):
      {legend}
    -

    Track: {esc(src.get("line_source", ""))}, read {esc(src.get("source_checked", ""))}, drawn simplified to 30 m. Credit: {esc(credit)} {common.TRAIL_MAP_CREDIT}

    +

    Track: {esc(src.get("line_source", ""))}, read {esc(src.get("source_checked", ""))}, drawn simplified to 30 m.

    """ +def map_credit(rec): + """The credit of the map, beside it under the downloads: the track's source, the base map and the + relief. "" for a trail with no map.""" + has_track = common.has_line(rec) + if not has_track and not hike.sketch_points(rec): + return "" + track = "" + if has_track: + credit = common.sentence(common.credit_text(rec["source"].get("attribution", ""))) + track = f"

    Track credit: {esc(credit)}

    " + return f"""
    +

    Map credit

    + {track}

    {common.TRAIL_MAP_CREDIT}

    +
    """ + + def elevation_figure(rec): """The elevation profile under the map, drawn as SVG at build time. With too many parts (olt/elevation.py) there is no line to draw in walking order, so @@ -828,7 +863,6 @@ def sketch_figure(rec):

    {reason_html}

    {esc(rule)}

    {actions_html} -

    {common.TRAIL_MAP_CREDIT}

    """ @@ -1056,11 +1090,11 @@ def policy_scale(current): return Markup(f'
      {"".join(items)}
    ') -def route_block(rec): +def route_block(rec, author_links=None): r = rec["route"] p = r.get("line_policy", "") rows = [ - fact("Author", r.get("creator", ""), "Who worked the route out (route.creator)"), + fact("Author", credit_html(rec, r.get("creator", ""), author_links) if r.get("creator") else "", "Who worked the route out (route.creator)"), fact("First published", str(r["year"])) if r.get("year") else fact("First published", "Not recorded", "No page read states a year"), fact("Track policy", words.label(words.POLICIES, p), words.meaning(words.POLICIES, p)), @@ -1074,7 +1108,7 @@ def route_block(rec): quote = f"""

    {esc(r["creator_words"])}

    -

    {esc(by)} {not_creator}

    +

    {esc(by) if r.get("creator_words_by") else credit_html(rec, by, author_links)} {not_creator}

    {f'

    Read on {ext_link(url)}.

    ' if url else ""}
    """ @@ -1430,9 +1464,9 @@ def hike_sources_block(rec): return block("hike-title", "Where the hiking facts come from", Markup(body + checked)) -def about_data(rec, site): +def about_data(rec, site, author_links=None): """Everything about where the page's data comes from: collapsed, below the hiker's part.""" - blocks = ((route_block(rec) if common.is_route(rec) else "") + record_block(rec) + hike_sources_block(rec) + blocks = ((route_block(rec, author_links) if common.is_route(rec) else "") + record_block(rec) + hike_sources_block(rec) + verification_block(rec) + elevation_block(rec) + source_block(rec) + osm_block(rec) + logo_block(rec) + links_block(rec) + correction_block(rec, site) + raw_record(rec)) return f"""
    @@ -1517,16 +1551,13 @@ def raw_value(value): def raw_record(rec): """Every field of the record with its exact value, as the last block of the page.""" fields = {k: v for k, v in rec.items() if k != "derived"} - rows = "".join(f'{esc(field)}{esc(raw_value(value))}' + rows = "".join(f'
    {esc(field)}
    {esc(raw_value(value))}
    ' for field, value in flatten(fields)) return Markup(f"""
    Every field of the record, with its exact value

    As stored in trail.toml. The record schema says what each field means.

    -
    - - {rows} -
    FieldValue
    +
    {rows}
    """) @@ -1695,22 +1726,19 @@ def render(rec, site, records=None, author_links=None): aside_html = (f'') if aside else "" profile = elevation_figure(rec) - side = f'
    {glance(rec, records)}{aside_html}
    ' + side = f'
    {glance(rec, records)}{aside_html}{map_credit(rec)}
    ' body = f"""{page_head(rec, author_links)}
    -
    - {lead_text(rec)} - {action_buttons(rec)} -
    - {side} + {strip(rec)} {map_figure(rec) if has_track else sketch_figure(rec) if sketch_points else empty_frame(rec)} + {side} +
    {trail_text(rec)}
    {profile}
    - {trail_text(rec)} {onward(rec, records)} {page_foot(rec, site)} - {about_data(rec, site)} + {about_data(rec, site, author_links)} {history_section(rec)}
    """ return page_title(rec, site), description(rec), body, has_map diff --git a/web/olt/views.py b/web/olt/views.py index 20a7513..bb59ac6 100644 --- a/web/olt/views.py +++ b/web/olt/views.py @@ -67,17 +67,17 @@ def recent_page(records, site): changes, total = recent_changes(records) newest = seo.newest(records) groups = [(f"Added {d} ({len(rs)})", rs, None) for d, rs in added] - rows = [[d, pagekit.trail_link(r), change] for d, r, change in changes] + items = [pagekit.plain_entry(pagekit.trail_link(r), heading=False, text=[esc(change)], + small=[f'']) for d, r, change in changes] lede = (f"The {len(recs)} newest additions, from each trail’s own history, and the newest of the {total} changes " f"made to a trail’s facts. The newest date in the data is {esc(newest)}.") body = (pagekit.head("Recently added and changed", lede, [("Trails", "/"), ("Lists", "/lists/")]) + f"""
    -

    Newly added trails

    - {home.results(groups=groups, top=3)}
    -

    Newest changes

    - {pagekit.table(["Date", "Trail", "What changed"], rows, caption="The newest changes")} +

    Newly added trails

    + {home.browse_view(home.results(groups=groups, top=3), home.overview_map(recs, "Map of the newest trails"), + about=f"""{pagekit.plain_list(items, "The newest changes")}

    Each trail keeps its own history, shown at the foot of its page. The - changelog lists changes to the site and the dataset as a whole.

    + changelog lists changes to the site and the dataset as a whole.

    """, about_title="Newest changes", about_id="newest-changes")}
    """) title = "Recently Added Long Hiking Trails and Changes" desc = common.cut_at_word(f"The {len(recs)} newest long hiking trails and the newest changes to them, " diff --git a/web/tests/test_extra.py b/web/tests/test_extra.py index ba7bf5a..8844fbb 100644 --- a/web/tests/test_extra.py +++ b/web/tests/test_extra.py @@ -68,6 +68,40 @@ class ExtraPagesTest(unittest.TestCase): self.assertIn(f'href="/trails/{r["id"]}/"', page, r["id"]) self.assertIn(r["route"]["creator"], text, r["id"]) + def test_ways_into_the_authors_pages_are_routes(self): + """A route's row names its author as a link to their page (each named person who has one); + the Routes page head counts routes and authors and links /authors/; /lists/ lists Route + authors beside Routes; the trail page links the author where it names them.""" + import html as _html + from olt import authors + routes = [r for r in self.records if r["derived"]["kind"] == "route"] + gs = authors.author_pages(self.records, ROOT) + links = authors.link_map(self.records, ROOT) + row = re.compile(r'

    (.*?)

    ') + home = read_out("index.html") + by_line = {m for m in row.findall(home)} + for r in routes: + for name, href in links.get(r["route"]["creator"], []): + self.assertIn(f'{_html.escape(name)}', "".join(by_line), r["id"]) + # a credit with two people links each; a credit with no page stays plain + self.assertTrue(any(len(v) > 1 for v in links.values())) + self.assertEqual(len(gs), len({n for v in links.values() for n, _ in v})) + # Routes page head + page = read_out("routes/index.html") + head = page[:page.index('
    ')] + self.assertIn(f'

    {len(routes)} routes by {len(gs)} authors

    ', head) + # Lists index: in the group Routes is in + lists = read_out("lists/index.html") + group = lists[lists.index('id="group-standing"'):] + group = group[:group.index("")] + self.assertIn('Routes', group) + self.assertIn('Route authors', group) + # the trail page links the author's name in its head and its Author fact + for r in routes: + for name, href in links.get(r["route"]["creator"], []): + trail_page = read_out(f"trails/{r['id']}/index.html") + self.assertGreaterEqual(trail_page.count(f''), 2, r["id"]) + def test_every_logo_on_logos_page(self): page = read_out("logos/index.html") for r in self.records: @@ -185,9 +219,9 @@ class ExtraPagesTest(unittest.TestCase): # no dataset filters for name in ("tier", "policy", "designated", "line", "country", "region"): self.assertNotIn(f'name="{name}"', form, name) - # the map is in the tool, beside the list it filters (after it in the page, beside it on a wide screen) - main = doc[doc.index('
    '):] - self.assertLess(main.index('
      '):] + self.assertLess(main.index('data-map="overview"'), main.index('
        ", form.index('id="max"'))] minsel = form[form.index('id="min"'):form.index("", form.index('id="min"'))] @@ -221,9 +255,9 @@ class ExtraPagesTest(unittest.TestCase): self.assertIn(f"
        Track measured
        {measured}<", page) self.assertIn("
        Source status: OpenStreetMap only
        ", page) # a record's "none (no line included)" is shown in words, not as the raw value - self.assertIn("None (no track included)", page) + self.assertIn('

        None (no track included)

        ', page) self.assertNotIn("none (no line included)", page) - self.assertEqual(page.count('Trails'), 2) + self.assertNotIn("
        [^<]*, ') for name in ("all-gpx.zip", "all-geojson.zip"): size = words.fmt_bytes(os.path.getsize(os.path.join(OUT, "data", name))) - self.assertRegex(page, rf'/data/{re.escape(name)}[^<]*{re.escape(size)}<') + self.assertRegex(page, rf'/data/{re.escape(name)}

        .*? {re.escape(size)}<') self.assertIn(f'"contentUrl":"{site.load().base_url}/data/{name}"', page) def test_archives_hold_every_line(self): diff --git a/web/tests/test_first_screen.py b/web/tests/test_first_screen.py index 50ab16b..88edcce 100644 --- a/web/tests/test_first_screen.py +++ b/web/tests/test_first_screen.py @@ -1,6 +1,7 @@ """The first screen: what the top of the trail page and the home page hold, the home page's lists -(read from data), the header's Lists item, the tables that stack on a phone, and the maps' static -drawings (olt/sketch.py) with the script's handover from them. +(read from data), the header's Lists item, the shared layout of every page that shows a set of +trails, the rows that take the place of tables, and the maps' static drawings (olt/sketch.py) with +the script's handover from them. Pages are rendered one at a time; the site is not built. The sketch reads the track files of a site directory, so those are written to a temporary one here. The behaviour of the script in a @@ -56,15 +57,23 @@ class HomePageTest(unittest.TestCase): self.assertEqual(keys, ["national-scenic-trails", "routes", "high-routes", "loops", "under-100-miles", "a-week-or-less", "one-to-two-weeks", "a-month-or-more", "with-gpx", "canada"]) row = home.lists_row(self.recs, keys) - titles = re.findall(r'
      1. (.*?) ', row) + titles = re.findall(r'
      2. (.*?)', row) self.assertEqual(titles, [browse.by_key(k).title for k in keys]) self.assertTrue(row.rstrip().endswith("")) - self.assertIn('All lists', row) + self.assertIn('
      3. All lists
      4. ', row) self.assertNotIn("Hiking in", row) + self.assertNotIn("chips", row) # one quiet line of links, not pills # a different file gives a different row: the set is not a constant of the generator other = home.home_picks([{"key": "loops", "home": 2}, {"key": "routes", "home": 1}, {"key": "canada"}]) self.assertEqual(other, ["routes", "loops"]) - self.assertEqual(re.findall(r'
      5. (.*?) (.*?)'):] + self.assertLess(grid.index('class="browse__map" id="map"'), grid.index('class="browse__list"')) + self.assertLess(grid.index('class="browse__list"'), grid.index('id="finder-form"')) + self.assertLess(grid.index('id="finder-form"'), grid.index('id="entries"')) + self.assertNotIn("filters__maplink", self.body) - def test_the_stylesheet_puts_the_map_beside_the_list_on_a_wide_screen(self): + def test_the_open_filters_lie_over_the_rows_and_can_be_closed(self): css = read(WEB, "assets", "style.css") - self.assertRegex(css, r"\.home \{[^}]*grid-template-areas: \"lists\" \"bar\" \"results\" \"map\" \"notes\"") - self.assertIn('grid-template-areas: "lists lists" "bar map" "results map" "notes ."', css) - self.assertRegex(css, r"\.lists-row \.chips \{[^}]*flex-wrap: nowrap; overflow-x: auto") + self.assertRegex(css, r"html\.js \.filters__panels \{[^}]*position: absolute;") + self.assertIn('class="button filters__done"', self.body) + js = read(WEB, "assets", "app.js") + self.assertIn("e.key === 'Escape'", js) class ListEntriesCheckTest(unittest.TestCase): @@ -150,36 +163,57 @@ class HeaderTest(unittest.TestCase): self.assertIn("layout.UNDER_LISTS.add(path)", read(WEB, "olt", "pages.py")) -class TablesTest(unittest.TestCase): - def test_every_cell_carries_its_label_and_a_wide_table_is_set_by_row(self): - t = str(pagekit.table(["Trail", "Length", "States", "Time"], [["A", "1", "X", "2"]], caption="c")) - self.assertIn('', t) - self.assertEqual(re.findall(r'data-label="([^"]+)"', t), ["Trail", "Length", "States", "Time"]) - small = str(pagekit.table(["A", "B", "C"], [["1", "2", "3"]])) - self.assertNotIn("data-stack", small) +class NoTablesTest(unittest.TestCase): + """The site sets no tables. A set of trails is the site's trail rows; a set of other things is + rows in the same language (pagekit.rows_list); a table written in Markdown is set the same way.""" - def test_a_compare_table_labels_each_cell_with_its_row_and_stacks_by_column(self): - t = str(pagekit.table(["Figure", "AT", "PCT"], [["Length", "2,198", "2,650"], ["States", "14", "3"]], - row_heads=True, compare=True)) - self.assertIn('
        ', t) - self.assertEqual(re.findall(r'', table, re.S)} + for f, v in re.findall(r'
        (.*?)
        (.*?)
        ', listing, re.S)} fields = dict(leaves(raw)) self.assertEqual(set(rows), set(fields), rec["id"]) for field, value in fields.items(): @@ -445,7 +456,7 @@ class RenderUnitTest(unittest.TestCase): 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'

        .*?

        ', trail.action_buttons(rec), re.S).group(0) + buttons = re.search(r'

        .*?

        ', trail.action_buttons(rec), re.S).group(0) self.assertIn("Official site", buttons) self.assertNotIn("wiki.example", buttons) @@ -453,7 +464,7 @@ class RenderUnitTest(unittest.TestCase): 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'

        .*?

        ', trail.action_buttons(rec), re.S).group(0) + buttons = re.search(r'

        .*?

        ', trail.action_buttons(rec), re.S).group(0) self.assertIn('href="https://wiki.example/t"', buttons) self.assertIn("Wiki Pub", buttons) self.assertNotIn("other.example", buttons) diff --git a/web/tests/test_saved.py b/web/tests/test_saved.py index 9cdf88d..e2009e7 100644 --- a/web/tests/test_saved.py +++ b/web/tests/test_saved.py @@ -175,7 +175,7 @@ class SaveButtonsTest(unittest.TestCase): def test_every_trail_page_has_a_save_button_by_its_actions(self): for rec in self.records: doc = read_out(f"trails/{rec['id']}/index.html") - actions = doc[doc.index('

        '):doc.index("

        ", doc.index('

        '))] + actions = doc[doc.index('

        '):doc.index("

        ", doc.index('

        '))] m = re.search(r'

        ', t) + self.assertLess(t.index('class="entry__name">a.json'), t.index('class="entry__desc">Every trail')) + self.assertIn('', t) - def test_the_triple_crown_table_is_a_compare_table_with_equal_columns(self): + def test_a_table_written_in_markdown_or_by_hand_is_set_as_rows(self): + html = ('

        x

        ' + '
        TierRecords
        Measured12
        Stated3

        y

        ') + out = pagekit.untable(html) + self.assertNotIn("(\w+)<', out), ["Measured", "Stated"]) + self.assertTrue(out.startswith("

        x

        ") and out.endswith("

        y

        ")) + + def test_the_triple_crown_is_three_trail_rows_with_their_map_and_the_compared_figures_in_each_row(self): from olt import standing recs = records.load_records(ROOT) c = datafiles.collections(ROOT)[0] - title, desc, body, _ = standing.collection_page(c, recs, SITE) - self.assertIn('data-stack="columns"', str(body)) - css = read(WEB, "assets", "style.css") - self.assertIn('table[data-stack="columns"] { table-layout: fixed;', css) - self.assertIn('th:first-child { inline-size: 9rem; }', css) - self.assertIn("order: 3", css) # one block per trail on a phone, from the same cells - self.assertNotIn("min-inline-size: 34rem !important", css) + title, desc, body, members = standing.collection_page(c, recs, SITE) + body = str(body) + self.assertNotIn("High point", body) + self.assertIn("
        Designated
        ", body) - def test_the_left_out_tables_stack_on_a_phone_too(self): + def test_a_ranking_is_the_trail_rows_in_rank_order_led_by_the_rank_and_the_figure(self): + from olt import standing + recs = records.load_records(ROOT) + title, desc, body, have = standing.ranking_page(standing.RANKINGS[0], recs, SITE) + body = str(body) + self.assertNotIn("No. 1', first) + self.assertIn('
        (.*?)(.*?)