diff --git a/web/assets/app.js b/web/assets/app.js index 3e57e08..3f72877 100644 --- a/web/assets/app.js +++ b/web/assets/app.js @@ -33,7 +33,7 @@ var t = root.dataset.theme; return t ? t === 'dark' : darkQuery.matches; } - function milesFirst() { return root.dataset.units === 'mi'; } + function milesFirst() { return root.dataset.units !== 'km'; } function setTheme(value) { if (value === 'light' || value === 'dark') root.dataset.theme = value; @@ -43,10 +43,10 @@ } function setUnits(value) { - if (value === 'mi') root.dataset.units = 'mi'; + if (value === 'km') root.dataset.units = 'km'; else delete root.dataset.units; - writePref('lh-units', value === 'mi' ? 'mi' : null); - syncRadios('input[name="units"], input[name="units-list"]', value === 'mi' ? 'mi' : 'km'); + writePref('lh-units', value === 'km' ? 'km' : null); + syncRadios('input[name="units"], input[name="units-list"]', value === 'km' ? 'km' : 'mi'); document.dispatchEvent(new Event('olt:units')); } @@ -66,7 +66,7 @@ if (!root.dataset.theme) document.dispatchEvent(new Event('olt:theme')); }); - /* A length in both units, in the reader's order: "1,287 km (800 mi)". */ + /* A length in both units, in the reader's order: "800 mi (1,287 km)". */ function lengthText(km) { var k = fmt.format(km) + ' km'; var m = fmt.format(Math.round(km / KM_PER_MI)) + ' mi'; @@ -838,16 +838,19 @@ } function read() { - var min = Number(el.min.value) || 0; - var max = Number(el.max.value) || Infinity; + var min = stepKm(el.min.value) || 0; + var max = stepKm(el.max.value) || Infinity; + var minRaw = el.min.value, maxRaw = el.max.value; var swapped = min > max; - if (swapped) { var keep = min; min = max; max = keep; } + if (swapped) { var keep = min; min = max; max = keep; keep = minRaw; minRaw = maxRaw; maxRaw = keep; } var s = { q: el.q.value.trim(), words: el.q.value.trim().toLowerCase().split(/\s+/).filter(Boolean), where: el.where.value, min: min, max: max, + minRaw: minRaw, + maxRaw: maxRaw, swapped: swapped, month: el.month ? el.month.value : '', kind: radio('kind') @@ -875,27 +878,68 @@ return true; } - function lengthLabel(km) { - var k = fmt.format(km) + ' km'; - var m = fmt.format(Math.round(km / KM_PER_MI)) + ' mi'; - return milesFirst() ? m + ' · ' + k : k + ' · ' + m; + /* A length step's value is "100mi" or "160km": round in its own unit, so the + list offered follows the reader's units. Filtering compares kilometres. */ + function stepKm(value) { + var m = /^(\d+(?:\.\d+)?)(mi|km)$/.exec(value || ''); + return m ? Number(m[1]) * (m[2] === 'mi' ? KM_PER_MI : 1) : 0; + } + + function stepLabel(n, unit) { + var km = unit === 'mi' ? n * KM_PER_MI : n; + var other = unit === 'mi' ? fmt.format(Math.round(km)) + ' km' : fmt.format(Math.round(km / KM_PER_MI)) + ' mi'; + return fmt.format(n) + ' ' + unit + ' \u00b7 ' + other; + } + + /* Offer round steps in the reader's units. The server writes the mile steps; + a reader who chose kilometres gets the kilometre steps (data-steps-km), and + a chosen step moves to the nearest one in the new list. */ + function buildLengthOptions() { + var unit = milesFirst() ? 'mi' : 'km'; + form.querySelectorAll('select[data-length-options]').forEach(function (select) { + var kind = select.dataset.lengthOptions; + var steps = (select.getAttribute('data-steps-' + unit) || '').split(',').filter(Boolean).map(Number); + var wasKm = stepKm(select.value); + select.textContent = ''; + function add(value, text, selected) { + var o = document.createElement('option'); + o.value = value; + o.textContent = text; + if (selected) o.selected = true; + select.appendChild(o); + } + if (kind === 'min') add('', 'Any', false); + steps.slice(kind === 'min' ? 0 : 1, kind === 'min' ? -1 : undefined).forEach(function (n) { + add(n + unit, stepLabel(n, unit), false); + }); + if (kind === 'max') add('', 'Any', !wasKm); + if (wasKm) { + var best = null, gap = Infinity; + Array.prototype.forEach.call(select.options, function (o) { + var k = stepKm(o.value); + if (!k) return; + var d = Math.abs(Math.log(k / wasKm)); + if (d < gap) { gap = d; best = o; } + }); + if (best) best.selected = true; + } + }); } function describeLength(s) { var text; if (!s.min && s.max === Infinity) text = 'Any length.'; - else if (!s.min) text = 'Up to ' + lengthText(s.max) + '.'; - else if (s.max === Infinity) text = 'From ' + lengthText(s.min) + ' up.'; - else text = 'From ' + lengthText(s.min) + ' to ' + lengthText(s.max) + '.'; + else if (!s.min) text = 'Up to ' + lengthText(Math.round(s.max)) + '.'; + else if (s.max === Infinity) text = 'From ' + lengthText(Math.round(s.min)) + ' up.'; + else text = 'From ' + lengthText(Math.round(s.min)) + ' to ' + lengthText(Math.round(s.max)) + '.'; if (s.swapped) text += ' Shortest and longest were swapped.'; return text; } function relabelLengths() { - form.querySelectorAll('select[data-length-options] option').forEach(function (o) { - if (o.value) o.textContent = lengthLabel(Number(o.value)); - }); + buildLengthOptions(); setText(lenHint, describeLength(read())); + apply(true); } /* URL query <-> form. Only values that differ from the defaults are written. */ @@ -903,8 +947,8 @@ var p = new URLSearchParams(); if (s.q) p.set('q', s.q); if (s.where) p.set('where', s.where); - if (s.min) p.set('min', String(s.min)); - if (s.max !== Infinity) p.set('max', String(s.max)); + if (s.min) p.set('min', s.minRaw); + if (s.max !== Infinity) p.set('max', s.maxRaw); if (s.month) p.set('month', s.month); if (s.kind) p.set('kind', s.kind); MULTI.forEach(function (name) { if (s[name].length) p.set(name, s[name].join(',')); }); @@ -997,8 +1041,8 @@ li.addEventListener('focusout', function () { highlight(''); }); }); + buildLengthOptions(); fromQuery(); - relabelLengths(); applySort(); apply(false); /* The count can announce from here on; the first application is done. */ diff --git a/web/assets/apple-touch-icon.png b/web/assets/apple-touch-icon.png new file mode 100644 index 0000000..b1ceba7 Binary files /dev/null and b/web/assets/apple-touch-icon.png differ diff --git a/web/assets/favicon-32.png b/web/assets/favicon-32.png new file mode 100644 index 0000000..6c440b8 Binary files /dev/null and b/web/assets/favicon-32.png differ diff --git a/web/assets/favicon.svg b/web/assets/favicon.svg index 4153cf6..8857769 100644 --- a/web/assets/favicon.svg +++ b/web/assets/favicon.svg @@ -1 +1 @@ - + diff --git a/web/assets/og.png b/web/assets/og.png new file mode 100644 index 0000000..951297d Binary files /dev/null and b/web/assets/og.png differ diff --git a/web/assets/prefs.js b/web/assets/prefs.js index bce88eb..fff99cc 100644 --- a/web/assets/prefs.js +++ b/web/assets/prefs.js @@ -8,6 +8,6 @@ var theme = localStorage.getItem('lh-theme'); var units = localStorage.getItem('lh-units'); if (theme === 'light' || theme === 'dark') root.dataset.theme = theme; - if (units === 'mi') root.dataset.units = 'mi'; + if (units === 'km') root.dataset.units = 'km'; /* anything else, an old 'mi' included, is miles */ } catch (e) { /* storage blocked: defaults apply */ } })(); diff --git a/web/assets/style.css b/web/assets/style.css index a82f9b2..230caac 100644 --- a/web/assets/style.css +++ b/web/assets/style.css @@ -8,7 +8,7 @@ Themes: `color-scheme: light dark` follows prefers-color-scheme, and every colour token is written once with light-dark(). /assets/prefs.js pins a theme with and the length order with - (the footer switches set both). + (the footer switches set both); miles and feet come first without it. No inline styles except custom properties carrying data (--km, --n, --pos), which the Content-Security-Policy allows through style-src-attr. @@ -230,6 +230,7 @@ code.raw { .site-header { background: var(--paper); + border-block-start: 4px solid var(--trail); border-block-end: 3px double var(--rule-strong); } .site-header__inner { @@ -246,18 +247,15 @@ code.raw { align-items: center; gap: var(--space-3); color: var(--ink); - font: 650 1.3125rem/1 var(--font-serif); - letter-spacing: -0.01em; + font: 650 1.4375rem/1 var(--font-serif); + letter-spacing: -0.015em; text-decoration: none; } .wordmark:hover { text-decoration: none; } -/* The mark is a paint blaze, the sign hikers follow on a tree. */ -.wordmark__blaze { - inline-size: 0.6rem; - block-size: 1.4rem; - background: var(--trail); - border-radius: 1px 2px 1px 3px; -} +/* The mark: a mountain with a trail up it, the same file as the tab icon. */ +.wordmark__mark { inline-size: 1.75rem; block-size: 1.75rem; } +/* The home page carries the name large in its hero, so the header does not repeat it. */ +body:has(.hero--home) .site-header .wordmark { visibility: hidden; } .nav { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-5); padding: 0; list-style: none; } @media (max-width: 30rem) { .nav { column-gap: var(--space-4); } } @@ -323,24 +321,25 @@ code.raw { /* 5. Shared components ------------------------------------------------------- */ /* Lengths in both units. The reader's preference (html[data-units]) decides - which comes first; markup is always . - .len--inline reads "1,287 km (800 mi)"; .len--stack sets the first unit + which comes first: miles and feet unless the reader chose "km"; markup is + always . + .len--inline reads "800 mi (1,287 km)"; .len--stack sets the first unit large over the second. */ .len { display: inline-flex; flex-wrap: wrap; align-items: baseline; column-gap: 0.3em; } -.len__mi { order: 1; } -:root[data-units="mi"] .len__mi { order: -1; } -.len--inline .len__mi::before, -:root[data-units="mi"] .len--inline .len__km::before { content: "("; } -.len--inline .len__mi::after, -:root[data-units="mi"] .len--inline .len__km::after { content: ")"; } -:root[data-units="mi"] .len--inline .len__mi::before, -:root[data-units="mi"] .len--inline .len__mi::after { content: none; } +.len__km { order: 1; } +:root[data-units="km"] .len__km { order: -1; } +.len--inline .len__km::before, +:root[data-units="km"] .len--inline .len__mi::before { content: "("; } +.len--inline .len__km::after, +:root[data-units="km"] .len--inline .len__mi::after { content: ")"; } +:root[data-units="km"] .len--inline .len__km::before, +:root[data-units="km"] .len--inline .len__km::after { content: none; } .len--stack { display: flex; flex-direction: column; align-items: flex-start; } .len--stack > * { font-variant-numeric: tabular-nums; } -:root:not([data-units="mi"]) .len--stack .len__km, -:root[data-units="mi"] .len--stack .len__mi { font: 600 var(--len-size, var(--step-1))/1.15 var(--font-sans); color: var(--ink); } -:root:not([data-units="mi"]) .len--stack .len__mi, -:root[data-units="mi"] .len--stack .len__km { font: 400 var(--step--1)/1.3 var(--font-sans); color: var(--ink-2); } +:root:not([data-units="km"]) .len--stack .len__mi, +:root[data-units="km"] .len--stack .len__km { font: 600 var(--len-size, var(--step-1))/1.15 var(--font-sans); color: var(--ink); } +:root:not([data-units="km"]) .len--stack .len__km, +:root[data-units="km"] .len--stack .len__mi { font: 400 var(--step--1)/1.3 var(--font-sans); color: var(--ink-2); } /* Kicker: a small caps label above a title */ .kicker { @@ -748,15 +747,42 @@ code.raw { .hero::before { content: ""; position: absolute; - inset: 0; + 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: linear-gradient(100deg, transparent 15%, #000 70%); - mask-image: linear-gradient(100deg, transparent 15%, #000 70%); + /* The lines belong to the content column: on a wide window they stay inside it + and do not run on to the right edge of the screen. They spread from the + column's top right and thin out to nothing toward the text, the bottom of + the band and the column's right edge, so they never stop on a straight line. */ + -webkit-mask-image: radial-gradient(ellipse 70% 104% at 90% 0%, #000 0%, rgb(0 0 0 / 0.7) 30%, rgb(0 0 0 / 0.28) 58%, transparent 84%), linear-gradient(to right, #000 82%, transparent 100%); + mask-image: radial-gradient(ellipse 70% 104% at 90% 0%, #000 0%, rgb(0 0 0 / 0.7) 30%, rgb(0 0 0 / 0.28) 58%, transparent 84%), linear-gradient(to right, #000 82%, transparent 100%); + -webkit-mask-composite: source-in; + mask-composite: intersect; pointer-events: none; } .hero__inner { position: relative; display: grid; gap: var(--space-5); } .hero h1 { max-inline-size: 28ch; font-size: var(--step-4); font-weight: 600; letter-spacing: -0.015em; } .hero__lede { max-inline-size: 40rem; font-size: var(--step-1); line-height: 1.5; } +/* The home page's name plate: mark, name, what the site is, and what it offers. */ +.hero .lockup { + display: flex; align-items: center; gap: clamp(0.75rem, 2.4vw, 1.75rem); + max-inline-size: none; + font-size: clamp(2.75rem, 1.2rem + 7vw, 6rem); font-weight: 600; line-height: 1; letter-spacing: -0.02em; +} +.lockup__mark { flex: none; inline-size: 1.15em; block-size: 1.15em; } +.hero__tagline { max-inline-size: 26em; font: 400 var(--step-3)/1.25 var(--font-serif); } +.hero__tags { + display: flex; flex-wrap: wrap; gap: var(--space-1) 0; padding: 0; list-style: none; + color: var(--ink-2); font: 600 var(--step-0)/1.4 var(--font-sans); letter-spacing: 0.09em; text-transform: uppercase; +} +/* Each item carries its dot on the left; the list is shifted and clipped by the + same amount so a dot never starts a line. */ +.hero__tags { margin-inline-start: -1.7em; clip-path: inset(0 0 0 1.7em); } +.hero__tags li { position: relative; padding-inline-start: 1.7em; } +.hero__tags li::before { content: "\00B7"; position: absolute; inset-inline-start: 0.65em; } +.hero__tags a { color: inherit; text-decoration: none; } +.hero__tags a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 0.2em; } +.hero--home .hero__lede { color: var(--ink-2); font-size: var(--step-0); } .hero__caveat { max-inline-size: 40rem; padding-inline-start: var(--space-4); @@ -993,7 +1019,7 @@ html:not(.js) .list-head__arrow { display: none; } .entry__facts dd { margin: var(--space-1) 0 0; } /* Length strip on a log scale: 50 km at the left edge, 30,000 km at the right. - Ticks mark 100, 1,000 and 10,000 km. Uses CSS log(); without it the strip + Ticks mark 100, 1,000 and 10,000 miles, or kilometres when the reader chose them. Uses CSS log(); without it the strip shows ticks only. */ .loglen { --tick: var(--rule-strong); @@ -1005,6 +1031,12 @@ html:not(.js) .list-head__arrow { display: none; } } @supports (inline-size: calc(log(2) * 1%)) { .loglen { + background: + linear-gradient(var(--tick) 0 0) calc(log(100 * 1.609344 / 50) / log(600) * 100%) 100% / 1px 100% no-repeat, + linear-gradient(var(--tick) 0 0) calc(log(1000 * 1.609344 / 50) / log(600) * 100%) 100% / 1px 100% no-repeat, + linear-gradient(var(--tick) 0 0) calc(log(10000 * 1.609344 / 50) / log(600) * 100%) 100% / 1px 100% no-repeat; + } + :root[data-units="km"] .loglen { background: linear-gradient(var(--tick) 0 0) calc(log(2) / log(600) * 100%) 100% / 1px 100% no-repeat, linear-gradient(var(--tick) 0 0) calc(log(20) / log(600) * 100%) 100% / 1px 100% no-repeat, @@ -1101,13 +1133,17 @@ html:not(.js) .list-head__arrow { display: none; } .list-head__sort.is-active .list-head__arrow { color: var(--trail); } .list-head__scale { position: relative; display: block; block-size: 1em; margin-block-start: var(--space-1); font: 400 0.6875rem/1 var(--font-mono); letter-spacing: 0; text-transform: none; } .list-head__scale > span { position: absolute; transform: translateX(-50%); white-space: nowrap; } - .list-head__scale > span:nth-child(1) { inset-inline-start: 10.8%; } - .list-head__scale > span:nth-child(2) { inset-inline-start: 46.8%; } - .list-head__scale > span:nth-child(3) { inset-inline-start: 82.8%; } + /* Ticks at 100, 1,000 and 10,000 miles (the strip itself is on a kilometre scale). */ + .list-head__scale > span:nth-child(1) { inset-inline-start: 18.3%; } + .list-head__scale > span:nth-child(2) { inset-inline-start: 54.3%; } + .list-head__scale > span:nth-child(3) { inset-inline-start: 90.3%; } + :root[data-units="km"] .list-head__scale > span:nth-child(1) { inset-inline-start: 10.8%; } + :root[data-units="km"] .list-head__scale > span:nth-child(2) { inset-inline-start: 46.8%; } + :root[data-units="km"] .list-head__scale > span:nth-child(3) { inset-inline-start: 82.8%; } /* One tick figure per mark, in the reader's units; the last carries the unit. */ - .list-head__scale .len__mi { display: none; } - :root[data-units="mi"] .list-head__scale .len__mi { display: inline; } - :root[data-units="mi"] .list-head__scale .len__km { display: none; } + .list-head__scale .len__km { display: none; } + :root[data-units="km"] .list-head__scale .len__km { display: inline; } + :root[data-units="km"] .list-head__scale .len__mi { display: none; } } .empty-state { @@ -1129,10 +1165,13 @@ html:not(.js) .list-head__arrow { display: none; } .page-head::before { content: ""; position: absolute; - inset: 0; + inset-block: 0; + inset-inline: max(0px, (100% - var(--container)) / 2 - var(--gutter)); background: url("contours.svg") 85% 40% / cover no-repeat; - -webkit-mask-image: linear-gradient(100deg, transparent 35%, #000 85%); - mask-image: linear-gradient(100deg, transparent 35%, #000 85%); + -webkit-mask-image: radial-gradient(ellipse 60% 104% at 90% 0%, #000 0%, rgb(0 0 0 / 0.7) 30%, rgb(0 0 0 / 0.28) 58%, transparent 84%), linear-gradient(to right, #000 82%, transparent 100%); + mask-image: radial-gradient(ellipse 60% 104% at 90% 0%, #000 0%, rgb(0 0 0 / 0.7) 30%, rgb(0 0 0 / 0.28) 58%, transparent 84%), linear-gradient(to right, #000 82%, transparent 100%); + -webkit-mask-composite: source-in; + mask-composite: intersect; opacity: 0.8; pointer-events: none; } @@ -1613,9 +1652,9 @@ td .linklist a { font-weight: 400; } .elev-profile__line { fill: none; stroke: var(--trail); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; } .elev-profile__mark { fill: var(--surface); stroke: var(--trail); stroke-width: 2; } /* One axis system at a time, by the reader's unit preference */ -.elev-profile .len__mi { display: none; } -:root[data-units="mi"] .elev-profile .len__mi { display: inline; } -:root[data-units="mi"] .elev-profile .len__km { display: none; } +.elev-profile .len__km { display: none; } +:root[data-units="km"] .elev-profile .len__km { display: inline; } +:root[data-units="km"] .elev-profile .len__mi { display: none; } /* Below the hiker's part: the plain foot line, then "About this data" */ .trail-more { padding-block: var(--space-6) var(--space-7); } @@ -1682,9 +1721,9 @@ td .linklist a { font-weight: 400; } .shelf__len { flex: none; color: var(--ink-2); font-variant-numeric: tabular-nums; } .shelf__more { font: 600 var(--step--1)/1.3 var(--font-sans); } /* One unit only in a card row, the reader's */ -.len--short .len__mi { display: none; } -:root[data-units="mi"] .len--short .len__mi { display: inline; } -:root[data-units="mi"] .len--short .len__km { display: none; } +.len--short .len__km { display: none; } +:root[data-units="km"] .len--short .len__km { display: inline; } +:root[data-units="km"] .len--short .len__mi { display: none; } .region-chips { margin-block-start: var(--space-6); } .region-chips h3 { margin-block-end: var(--space-3); font-size: var(--step-1); } @@ -1798,7 +1837,7 @@ a.tag:hover { background: var(--sunken); } /* The trail list where there is no room for columns (a phone, or beside the filters on a laptop): a compact card, not a table folded in on itself. Name, one or two lines of description, the place, then the facts on - one wrapping line ("420 km · About 4 weeks · Partial GPX here"). The labels, + one wrapping line ("260 mi · About 4 weeks · Partial GPX here"). The labels, the length strip, the second unit and the boxed notes are for wide rows; the trail's own page has all of it. */ @container results (max-width: 65.99rem) { @@ -1830,10 +1869,10 @@ a.tag:hover { background: var(--sunken); } .entry__facts dt { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } .entry__facts dd { margin: 0; font: inherit; } .entry__facts .len--stack { display: inline; } - :root:not([data-units="mi"]) .entry__facts .len--stack .len__km, - :root[data-units="mi"] .entry__facts .len--stack .len__mi { font: 600 var(--step--1)/1.5 var(--font-sans); } - :root:not([data-units="mi"]) .entry__facts .len--stack .len__mi, - :root[data-units="mi"] .entry__facts .len--stack .len__km { display: none; } + :root:not([data-units="km"]) .entry__facts .len--stack .len__mi, + :root[data-units="km"] .entry__facts .len--stack .len__km { font: 600 var(--step--1)/1.5 var(--font-sans); } + :root:not([data-units="km"]) .entry__facts .len--stack .len__km, + :root[data-units="km"] .entry__facts .len--stack .len__mi { display: none; } .entry__facts .loglen, .entry__facts .swatch, .entry__facts .line__detail, diff --git a/web/olt/browse.py b/web/olt/browse.py index 95a1cf5..10b2c1e 100644 --- a/web/olt/browse.py +++ b/web/olt/browse.py @@ -20,8 +20,12 @@ from . import common, facets, words MIN_SIZE = 4 MAX_SHARE = 0.75 -LONG_KM = 2000 -SHORT_KM = 100 +# The two lists defined by length are set in miles; membership compares the +# record's kilometres with the mile figure converted once, here. +LONG_MI = 1000 +SHORT_MI = 100 +LONG_KM = LONG_MI * words.KM_PER_MI +SHORT_KM = SHORT_MI * words.KM_PER_MI @dataclass(frozen=True) @@ -35,8 +39,8 @@ class List: sort: str = "name" -def _mi(km): - return words.fmt_int(words.km_to_mi(km)) +def _km(mi): + return words.fmt_int(mi * words.KM_PER_MI) def _band(key): @@ -50,10 +54,10 @@ LISTS = ( List("routes", "Routes", facets.ROUTE_DEFINITION, lambda r: facets.kind(r) == "route"), List("longest", "The longest", - f"Trails of {LONG_KM:,} km ({_mi(LONG_KM)} mi) or more.", + f"Trails of {LONG_MI:,} miles ({_km(LONG_MI)} km) or more.", lambda r: r["length_km"] >= LONG_KM, sort="length-desc"), - List("under-100-km", f"Under {SHORT_KM} km", - f"Trails shorter than {SHORT_KM} km ({_mi(SHORT_KM)} mi).", + List("under-100-miles", f"Under {SHORT_MI} miles", + f"Trails shorter than {SHORT_MI} miles ({_km(SHORT_MI)} km).", lambda r: r["length_km"] < SHORT_KM, sort="length-asc"), List("a-week-or-less", "A week or less", "Trails most people walk in a week or less, as a source states it or as estimated from the length.", diff --git a/web/olt/common.py b/web/olt/common.py index 6a53b2d..31e6382 100644 --- a/web/olt/common.py +++ b/web/olt/common.py @@ -42,11 +42,12 @@ def line_short(rec): def partial_short_text(rec): - """The short form for lists: "Track measures 2.0 km of 1,100 km published".""" + """The short form for lists: "Track measures 1.2 mi (2.0 km) of 684 mi (1,100 km) published", + in the reader's unit order (words.length). Markup.""" v = rec["verification"] word = "of" if v["difference_percent"] < 0 else "against" - return (f"Track measures {words.fmt_km1(v['measured_km'])} km {word} " - f"{words.fmt_km(rec['length_km'])} km published") + return Markup(f"Track measures {words.length(v['measured_km'], measured=True)} {word} " + f"{words.length(rec['length_km'], mi=rec['derived']['length_mi'])} published") def name(rec): diff --git a/web/olt/docs.py b/web/olt/docs.py index 7ced7ab..c6241a0 100644 --- a/web/olt/docs.py +++ b/web/olt/docs.py @@ -335,11 +335,11 @@ site calls them trails.

How trails are chosen

-

A trail is listed when it is a named, continuous walk, or a named loop, of at least 80 km (50 miles) +

A trail is listed when it is a named, continuous walk, or a named loop, of at least 50 miles (80 km) in the United States or Canada. It is either an official trail, looked after as one trail by a land agency or a trail association, or a route: {esc(facets.ROUTE_DEFINITION[0].lower() + facets.ROUTE_DEFINITION[1:])} {routes} of the {n} trails are routes. Every National Scenic Trail is listed, and a few well-known multi-day -trails between 60 and 80 km.

+trails between 37 and 50 miles (60 and 80 km).

Each record has a tier, which says why it is listed. A record can also be held: listed, but with something about it not yet settled, which its note says.

diff --git a/web/olt/elevation.py b/web/olt/elevation.py index 6be9b7f..6fdd436 100644 --- a/web/olt/elevation.py +++ b/web/olt/elevation.py @@ -123,12 +123,12 @@ def parts_caveat(elev): def plain_elevation(m): - """"2,025 m (6,644 ft)", for a sentence or a text alternative.""" - return f"{words.fmt_int(m)} m ({words.fmt_int(m / words.M_PER_FT)} ft)" + """"6,644 ft (2,025 m)", for a sentence or a text alternative.""" + return f"{words.fmt_int(words.m_to_ft(m))} ft ({words.fmt_int(m)} m)" def plain_length(km): - return f"{words.fmt_km1(km)} km ({words.fmt_int(words.km_to_mi(km))} mi)" + return f"{words.fmt_int(words.km_to_mi(km))} mi ({words.fmt_km1(km)} km)" def is_sea_level(point): @@ -204,7 +204,7 @@ LEFT, RIGHT, TOP, BOTTOM = 58, 14, 14, 40 def profile_svg(elev, loop=False): """The profile as inline SVG, drawn now, not by a script. Both unit systems - are drawn; CSS shows one, through the same len__km / len__mi pair and the + are drawn; CSS shows one, through the same len__mi / len__km pair and the reader's unit preference as every length on the site.""" profile = elev.get("profile") or [] if len(profile) < 2: @@ -283,4 +283,4 @@ def profile_svg(elev, loop=False): return Markup( f'' - f"{axis_group('km')}{axis_group('mi')}{axes}{line}{marks}") + f"{axis_group('mi')}{axis_group('km')}{axes}{line}{marks}") diff --git a/web/olt/facets.py b/web/olt/facets.py index 5933000..b5e010a 100644 --- a/web/olt/facets.py +++ b/web/olt/facets.py @@ -21,6 +21,7 @@ import re from functools import cmp_to_key from . import common, elevation, hike, words +from .markup import Markup # Facet names, exactly as every page shows them. WHERE, LENGTH, TIME, SEASON, TERRAIN, KIND, WALKING, SHAPE, GPX = ( @@ -155,8 +156,9 @@ def estimate_note(rec): if not time_days(rec)[2]: return "" slow, fast = pace(rec) - mi = f"{round(slow / words.KM_PER_MI)} to {round(fast / words.KM_PER_MI)} mi" - return f"Estimated from the length, at {slow} to {fast} km ({mi}) a day." + mi = f"{round(words.km_to_mi(slow))} to {round(words.km_to_mi(fast))} mi" + return Markup(f'Estimated from the length, at {mi}' + f'{slow} to {fast} km a day.') # Season --------------------------------------------------------------------- diff --git a/web/olt/home.py b/web/olt/home.py index d6e132e..593082d 100644 --- a/web/olt/home.py +++ b/web/olt/home.py @@ -10,21 +10,40 @@ import math from . import browse, common, facets, hike, words from .markup import Markup, esc -# Length range choices (km) for the filters. length_steps() adds a top step -# above the longest trail, so a chosen upper bound can always reach every trail. -LENGTH_STEPS = (60, 80, 100, 150, 200, 300, 500, 1000, 2000, 4000, 8000) +# Length range choices for the filters, round in the unit they are written in. +# Miles come first (the shortest trails are about 40 miles, the longest over +# 6,000); a reader who chose kilometres gets round kilometre steps. length_steps() +# adds a top step above the longest trail, so a chosen upper bound can always +# reach every trail. +LENGTH_STEPS_MI = (50, 75, 100, 150, 200, 300, 500, 1000, 2000, 4000, 8000) +LENGTH_STEPS_KM = (60, 80, 100, 150, 200, 300, 500, 1000, 2000, 4000, 8000) +LENGTH_STEPS = LENGTH_STEPS_MI -def length_steps(records): - """LENGTH_STEPS plus a round step at or above the longest trail, when that is longer.""" +def length_steps(records, unit="mi"): + """The round steps for the unit, plus a round step at or above the longest trail, when that is longer.""" longest = max((r["length_km"] for r in records), default=0) - steps = list(LENGTH_STEPS) + if unit == "mi": + longest = words.km_to_mi(longest) + steps = list(LENGTH_STEPS_MI if unit == "mi" else LENGTH_STEPS_KM) if longest > steps[-1]: magnitude = 10 ** int(math.floor(math.log10(longest))) steps.append(int(math.ceil(longest / magnitude) * magnitude)) return steps +def step_value(n, unit): + """The option value of a length step: "100mi" or "160km". app.js reads it the same way.""" + return f"{n}{unit}" + + +def step_label(n, unit): + """"100 mi · 161 km": the step in its own unit first.""" + if unit == "mi": + return f"{n:,} mi · {words.fmt_int(n * words.KM_PER_MI)} km" + return f"{n:,} km · {words.fmt_int(words.km_to_mi(n))} mi" + + def counts(records): """Counts for the filter options: each Where value, Time band, month, terrain, Kind, Walking, Shape and GPX status, as the filter would find them.""" @@ -95,7 +114,7 @@ def gpx_cell(rec): route = facets.kind(rec) == "route" if facets.gpx_here(rec): swatch = common.SWATCH_ROUTE if route else common.SWATCH_LINE - partial = (f'

{esc(common.partial_short_text(rec))}

' + partial = (f'

{common.partial_short_text(rec)}

' if common.line_differs(rec) else "") return (f'{swatch}{esc(facets.GPX_SHORT[status])}' f'GPX and GeoJSON{partial}') @@ -152,9 +171,8 @@ def entry(rec, *, level=3, extra="", routes_list=False): # The filters ------------------------------------------------------------------ -def _length_options(steps, selected_any_last): - opts = [f'' - for km in steps] +def _length_options(steps, selected_any_last, unit="mi"): + opts = [f'' for n in steps] if selected_any_last: return "".join(opts[1:]) + '' return '' + "".join(opts[:-1]) @@ -206,6 +224,7 @@ def finder_form(records, c=None, steps=None): """Search and the first-rank filters in view; Walking, Shape and GPX behind "More".""" c = c or counts(records) steps = steps or length_steps(records) + km_steps = length_steps(records, "km") first, more = [], [] first.append(f"""
@@ -215,10 +234,10 @@ def finder_form(records, c=None, steps=None): {facets.LENGTH}
- + - +

Any length.

""") @@ -292,8 +311,9 @@ def finder_form(records, c=None, steps=None): # The list --------------------------------------------------------------------- -# The length strip's ticks (style.css .loglen): 100, 1,000 and 10,000 km. -SCALE_KM = (100, 1000, 10000) +# The length strip's ticks (style.css .loglen): 100, 1,000 and 10,000 miles, or +# kilometres for a reader who chose them. Positions are in style.css. +SCALE_TICKS = (100, 1000, 10000) # Sort column of each sort key, and the arrow for its direction in the head. @@ -326,11 +346,10 @@ def list_head(sort_key="name"): """ sort_key = facets.normalize_sort(sort_key) ticks = [] - for i, km in enumerate(SCALE_KM): - unit = " km" if i == len(SCALE_KM) - 1 else "" - mi_unit = " mi" if i == len(SCALE_KM) - 1 else "" - ticks.append(f'{km:,}{unit}' - f'{words.fmt_int(words.km_to_mi(km))}{mi_unit}') + for i, n in enumerate(SCALE_TICKS): + last = i == len(SCALE_TICKS) - 1 + ticks.append(f'{n:,}{" mi" if last else ""}' + f'{n:,}{" km" if last else ""}') scale = f'{"".join(ticks)}' return f"""
TierWhat it meansRecords