Put miles and feet first, and give the site a proper mark
Units. Miles and feet now come first everywhere unless the reader chooses kilometres and metres: paired figures, the time estimate, the elevation profile, page descriptions and the map scale. The length filter and the length scale use round mile steps (round kilometre steps for a reader who chose them). The lists defined by length are now "Under 100 miles" and "The longest" at 1,000 miles or more; the old /lists/under-100-km/ address redirects. The records stay metric. Branding. The tab icon was a bare red blaze that read as a red block; it is now a mountain with a trail up it, with PNG sizes for browsers and phones that need them. The home page opens with the mark, the name and what the site offers. Link previews get a real 1200x630 image: the old one was an SVG, which Reddit, Slack and iMessage do not draw. The decorative contour lines now stay inside the content column and thin out to nothing on every side, where they used to run to the right edge of a wide window and stop dead at the bottom of the band. Tests updated for the new trail counts. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
c7e8e58dce
commit
19fabadd49
27 files changed
+480
-189
No files matched your search
+65
-21
@@ -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. */
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 942 B |
@@ -1 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><rect x="5" y="1" width="6" height="14" rx="1" fill="#b3261e"/></svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="7" fill="#b3261e"/><path d="M3.5 25.5 13 7.5l5.2 9.3 2.9-4.6 7.4 13.3z" fill="#f6f2e8"/><path d="M9.6 25.5c3.6-2.6 1-5 3-7.4 1.5-1.8.2-3.6.9-5.6" fill="none" stroke="#b3261e" stroke-width="2" stroke-linecap="round"/></svg>
|
||||
|
Before Width: | Height: | Size: 130 B After Width: | Height: | Size: 316 B |
Binary file not shown.
|
After Width: | Height: | Size: 153 KiB |
+1
-1
@@ -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 */ }
|
||||
})();
|
||||
+87
-48
@@ -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 <html data-theme="light|dark"> and the length order with
|
||||
<html data-units="mi"> (the footer switches set both).
|
||||
<html data-units="km"> (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 <span class="len"><km><mi></span>.
|
||||
.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 <span class="len"><mi><km></span>.
|
||||
.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,
|
||||
|
||||
+11
-7
@@ -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.",
|
||||
|
||||
+4
-3
@@ -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):
|
||||
|
||||
+2
-2
@@ -335,11 +335,11 @@ site calls them trails.</p>
|
||||
</section>
|
||||
|
||||
<section aria-labelledby="how-trails-are-chosen"><h2 id="how-trails-are-chosen">How trails are chosen</h2>
|
||||
<p>A trail is listed when it is a named, continuous walk, or a named loop, of at least 80 km (50 miles)
|
||||
<p>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.</p>
|
||||
trails between 37 and 50 miles (60 and 80 km).</p>
|
||||
<p>Each record has a <em>tier</em>, which says why it is listed. A record can also be <em>held</em>: listed,
|
||||
but with something about it not yet settled, which its note says.</p>
|
||||
<div class="table-wrap"><table><thead><tr><th scope="col">Tier</th><th scope="col">What it means</th><th scope="col">Records</th></tr></thead>
|
||||
|
||||
@@ -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'<svg class="elev-profile" viewBox="0 0 {W} {H}" role="img" '
|
||||
f'aria-label="{esc(summary_sentence(elev, loop))}" focusable="false">'
|
||||
f"{axis_group('km')}{axis_group('mi')}{axes}{line}{marks}</svg>")
|
||||
f"{axis_group('mi')}{axis_group('km')}{axes}{line}{marks}</svg>")
|
||||
+4
-2
@@ -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 <span class="len len--inline"><span class="len__mi">{mi}</span>'
|
||||
f'<span class="len__km">{slow} to {fast} km</span></span> a day.')
|
||||
|
||||
|
||||
# Season ---------------------------------------------------------------------
|
||||
|
||||
+51
-26
@@ -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'<p class="entry__partial">{esc(common.partial_short_text(rec))}</p>'
|
||||
partial = (f'<p class="entry__partial">{common.partial_short_text(rec)}</p>'
|
||||
if common.line_differs(rec) else "")
|
||||
return (f'<span class="line__status">{swatch}{esc(facets.GPX_SHORT[status])}</span>'
|
||||
f'<span class="line__detail">GPX and GeoJSON</span>{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'<option value="{km}">{km:,} km · {words.fmt_int(words.km_to_mi(km))} mi</option>'
|
||||
for km in steps]
|
||||
def _length_options(steps, selected_any_last, unit="mi"):
|
||||
opts = [f'<option value="{step_value(n, unit)}">{step_label(n, unit)}</option>' for n in steps]
|
||||
if selected_any_last:
|
||||
return "".join(opts[1:]) + '<option value="" selected>Any</option>'
|
||||
return '<option value="">Any</option>' + "".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"""<div class="field">
|
||||
<label class="field__label" for="where">{facets.WHERE}</label>
|
||||
@@ -215,10 +234,10 @@ def finder_form(records, c=None, steps=None):
|
||||
<legend>{facets.LENGTH}</legend>
|
||||
<div class="range">
|
||||
<label class="vh" for="min">Shortest length</label>
|
||||
<select class="select" id="min" name="min" data-length-options>{_length_options(steps, False)}</select>
|
||||
<select class="select" id="min" name="min" data-length-options="min" data-steps-mi="{",".join(map(str, steps))}" data-steps-km="{",".join(map(str, km_steps))}">{_length_options(steps, False)}</select>
|
||||
<span class="range__to" aria-hidden="true">to</span>
|
||||
<label class="vh" for="max">Longest length</label>
|
||||
<select class="select" id="max" name="max" data-length-options>{_length_options(steps, True)}</select>
|
||||
<select class="select" id="max" name="max" data-length-options="max" data-steps-mi="{",".join(map(str, steps))}" data-steps-km="{",".join(map(str, km_steps))}">{_length_options(steps, True)}</select>
|
||||
</div>
|
||||
<p class="field__hint" id="len-hint" aria-live="polite">Any length.</p>
|
||||
</fieldset>""")
|
||||
@@ -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'<span><span class="len__km">{km:,}{unit}</span>'
|
||||
f'<span class="len__mi">{words.fmt_int(words.km_to_mi(km))}{mi_unit}</span></span>')
|
||||
for i, n in enumerate(SCALE_TICKS):
|
||||
last = i == len(SCALE_TICKS) - 1
|
||||
ticks.append(f'<span><span class="len__mi">{n:,}{" mi" if last else ""}</span>'
|
||||
f'<span class="len__km">{n:,}{" km" if last else ""}</span></span>')
|
||||
scale = f'<span class="list-head__scale">{"".join(ticks)}</span>'
|
||||
return f"""<div class="list-head" aria-hidden="true">
|
||||
{_head_button("name", "Trail", sort_key)}
|
||||
@@ -344,8 +363,8 @@ def list_head(sort_key="name"):
|
||||
UNITS_TOGGLE = """<fieldset class="results-units">
|
||||
<legend class="vh">Lengths</legend>
|
||||
<div class="seg seg--small">
|
||||
<label><input type="radio" name="units-list" value="km" checked><span>km</span></label>
|
||||
<label><input type="radio" name="units-list" value="mi"><span>mi</span></label>
|
||||
<label><input type="radio" name="units-list" value="mi" checked><span>mi</span></label>
|
||||
<label><input type="radio" name="units-list" value="km"><span>km</span></label>
|
||||
</div>
|
||||
</fieldset>"""
|
||||
|
||||
@@ -535,17 +554,23 @@ def render(records, site):
|
||||
c = counts(records)
|
||||
recs = sorted(records, key=sort_name)
|
||||
total = c["total"]
|
||||
lede = (f"{total} long-distance trails in the United States and Canada. Narrow them by where they are, "
|
||||
f"how long they take, when to walk them and what the country is like. "
|
||||
f"{c['gpx_here']} have a GPX to download.")
|
||||
lede = (f"{total} trails. Narrow them by where they are, how long they take, when to walk them "
|
||||
f"and what the country is like. {c['gpx_here']} have a GPX to download.")
|
||||
contribute = ""
|
||||
if site.repo_url:
|
||||
contribute = (f'<p class="finder__foot">Something wrong, or a trail missing? '
|
||||
f'<a href="{esc(site.correction_url())}">Report a problem</a> or '
|
||||
f'<a href="{esc(site.new_trail_url)}">suggest a trail</a>.</p>')
|
||||
return f"""<section class="hero hero--short" aria-labelledby="hero-title">
|
||||
return f"""<section class="hero hero--short hero--home" aria-labelledby="hero-title">
|
||||
<div class="container hero__inner">
|
||||
<h1 id="hero-title">Find a long trail</h1>
|
||||
<h1 id="hero-title" class="lockup"><img class="lockup__mark" src="/assets/favicon.svg" alt="" width="96" height="96">{esc(site.name)}</h1>
|
||||
<p class="hero__tagline">Long-distance hiking trails of the United States and Canada, to compare and download.</p>
|
||||
<ul class="hero__tags">
|
||||
<li><a href="#finder">Filters</a></li>
|
||||
<li><a href="/lists/with-gpx/">GPX</a></li>
|
||||
<li><a href="/sources/">A source for every fact</a></li>
|
||||
<li><a href="/data/">Open data</a></li>
|
||||
</ul>
|
||||
<p class="hero__lede">{lede}</p>
|
||||
{lists_row(records)}
|
||||
</div>
|
||||
|
||||
+13
-7
@@ -56,7 +56,7 @@ def header(path, site):
|
||||
for text, href in NAV)
|
||||
return Markup(f"""<header class="site-header">
|
||||
<div class="container site-header__inner">
|
||||
<a class="wordmark" href="/"><span class="wordmark__blaze" aria-hidden="true"></span>{esc(site.name)}</a>
|
||||
<a class="wordmark" href="/"><img class="wordmark__mark" src="/assets/favicon.svg" alt="" width="28" height="28">{esc(site.name)}</a>
|
||||
<nav aria-label="Main"><ul class="nav">{items}</ul></nav>
|
||||
</div>
|
||||
</header>""")
|
||||
@@ -71,7 +71,7 @@ def footer(site):
|
||||
return Markup(f"""<footer class="site-footer">
|
||||
<div class="container site-footer__grid">
|
||||
<div class="site-footer__about">
|
||||
<a class="wordmark" href="/"><span class="wordmark__blaze" aria-hidden="true"></span>{esc(site.name)}</a>
|
||||
<a class="wordmark" href="/"><img class="wordmark__mark" src="/assets/favicon.svg" alt="" width="28" height="28">{esc(site.name)}</a>
|
||||
<p>Not for navigation: tracks vary in quality, some trails are unfinished, and some have no GPX here. Check a trail’s own maps before you go.</p>
|
||||
<p>The trail data is public domain (CC0-1.0). Each track keeps the terms of its source, named on its page. Tracks from OpenStreetMap are © OpenStreetMap contributors, under the ODbL. Logos belong to their holders and are shown only to identify each trail.</p>
|
||||
</div>
|
||||
@@ -106,8 +106,8 @@ def footer(site):
|
||||
<fieldset class="field">
|
||||
<legend>Units</legend>
|
||||
<div class="seg">
|
||||
<label><input type="radio" name="units" value="km" checked><span>km and m first</span></label>
|
||||
<label><input type="radio" name="units" value="mi"><span>mi and ft first</span></label>
|
||||
<label><input type="radio" name="units" value="mi" checked><span>mi and ft first</span></label>
|
||||
<label><input type="radio" name="units" value="km"><span>km and m first</span></label>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
@@ -154,19 +154,25 @@ def layout(title, body, *, path, description="", maps=False, scripts=(), data=No
|
||||
f'<meta property="og:description" content="{esc(description)}">',
|
||||
f'<meta property="og:type" content="{esc(og_type)}">',
|
||||
f'<meta property="og:site_name" content="{esc(site.name)}">',
|
||||
'<meta name="twitter:card" content="summary">',
|
||||
'<meta name="twitter:card" content="summary_large_image">',
|
||||
f'<meta name="twitter:title" content="{esc(full_title)}">',
|
||||
f'<meta name="twitter:description" content="{esc(description)}">',
|
||||
]
|
||||
if canonical:
|
||||
head.append(f'<meta property="og:url" content="{esc(canonical)}">')
|
||||
head.append(f'<meta property="og:image" content="{esc(site.canonical("/assets/favicon.svg"))}">')
|
||||
head.append(f'<meta name="twitter:image" content="{esc(site.canonical("/assets/favicon.svg"))}">')
|
||||
# A PNG: link previews (Reddit, Slack, iMessage) do not draw an SVG.
|
||||
image = esc(site.canonical("/assets/og.png"))
|
||||
head.append(f'<meta property="og:image" content="{image}">')
|
||||
head.append('<meta property="og:image:width" content="1200">')
|
||||
head.append('<meta property="og:image:height" content="630">')
|
||||
head.append(f'<meta name="twitter:image" content="{image}">')
|
||||
if jsonld is not None:
|
||||
head.append(str(_ld_json_block(jsonld)))
|
||||
head += [
|
||||
'<meta name="color-scheme" content="light dark">',
|
||||
'<link rel="icon" href="/assets/favicon.svg" type="image/svg+xml">',
|
||||
'<link rel="icon" href="/assets/favicon-32.png" type="image/png" sizes="32x32">',
|
||||
'<link rel="apple-touch-icon" href="/assets/apple-touch-icon.png">',
|
||||
]
|
||||
head += [f'<link rel="preload" href="{f}" as="font" type="font/woff2" crossorigin>' for f in FONT_PRELOADS]
|
||||
if maps:
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
import os
|
||||
import tomllib
|
||||
|
||||
from . import elevation
|
||||
from . import elevation, words
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
SHIELD_NAMES = ("shield.svg", "shield.png")
|
||||
@@ -50,7 +50,7 @@ def load_record(root, tid):
|
||||
rec["derived"] = {
|
||||
"kind": trail_kind(rec),
|
||||
"has_line": bool(rec.get("source", {}).get("line_file")),
|
||||
"length_mi": int(round(length_km / 1.609344)),
|
||||
"length_mi": int(round(length_km / words.KM_PER_MI)),
|
||||
"files": find_files(root, tid, rec),
|
||||
"elevation": elevation.load_file(root, tid),
|
||||
"status": trail_status(rec),
|
||||
|
||||
+6
-6
@@ -509,7 +509,7 @@ def download_group(rec, label, swatch, note, items, gid):
|
||||
f'<span class="button__meta">{esc(words.fmt_bytes(d["bytes"]))}</span></a>'
|
||||
for d in ordered_downloads(items))
|
||||
return f"""<li class="download">
|
||||
<p class="download__what">{swatch}<strong id="{gid}">{esc(label)}</strong><small>{esc(note)}</small></p>
|
||||
<p class="download__what">{swatch}<strong id="{gid}">{esc(label)}</strong><small>{note if isinstance(note, Markup) else esc(note)}</small></p>
|
||||
<div class="download__files">{buttons}</div>
|
||||
</li>"""
|
||||
|
||||
@@ -525,7 +525,7 @@ def partial_notice(rec):
|
||||
gap = rec["source"].get("length_gap_note", "")
|
||||
return f"""<div class="notice notice--partial">
|
||||
<h3>{head}</h3>
|
||||
<p>The track in the dataset measures {esc(words.fmt_km1(v["measured_km"]))} km against a published {esc(words.fmt_km(rec["length_km"]))} km ({esc(words.fmt_percent(diff))}).</p>
|
||||
<p>The track in the dataset measures {words.length(v["measured_km"], measured=True)} against a published {words.length(rec["length_km"], mi=rec["derived"]["length_mi"])} ({esc(words.fmt_percent(diff))}).</p>
|
||||
{f"<p>{common.rich(gap)}</p>" if gap else ""}
|
||||
</div>"""
|
||||
|
||||
@@ -542,8 +542,8 @@ def downloads_panel(rec):
|
||||
note = f"{src.get('line_source', '')}"
|
||||
if v.get("verified") and "measured_km" in v:
|
||||
parts = v.get("parts")
|
||||
note = (f"{words.fmt_km1(v['measured_km'])} km measured"
|
||||
+ (f" in {parts} part{'s' if parts != 1 else ''}" if parts else "") + f" · {note}")
|
||||
note = Markup(f"{words.length(v['measured_km'], measured=True)} measured"
|
||||
+ esc((f" in {parts} part{'s' if parts != 1 else ''}" if parts else "") + f" · {note}"))
|
||||
groups.append(download_group(rec, "Main track", common.SWATCH_ROUTE if common.is_route(rec) else common.SWATCH_LINE,
|
||||
note, main, "dl-main"))
|
||||
alts = [d for d in downloads if d["role"] == "alternates"]
|
||||
@@ -859,7 +859,7 @@ def elevation_block(rec):
|
||||
"No climb is counted across a gap."),
|
||||
]
|
||||
if starts:
|
||||
rows.append(fact("Part starts", ", ".join(words.fmt_km1(s) for s in starts) + " km",
|
||||
rows.append(fact("Part starts", words.distances(starts),
|
||||
"The distance along the profile where each part after the first begins"))
|
||||
if not elevation.show_profile(elev):
|
||||
rows.append(fact("Profile", "Not drawn", elevation.parts_caveat(elev)))
|
||||
@@ -1096,7 +1096,7 @@ def description(rec):
|
||||
else:
|
||||
km = words.fmt_km(rec["length_km"])
|
||||
mi = words.fmt_int(rec["derived"]["length_mi"])
|
||||
text = f"{rec['name']}: a {kind_word(rec)} of {km} km ({mi} mi) {place_text(rec)}."
|
||||
text = f"{rec['name']}: a {kind_word(rec)} of {mi} mi ({km} km) {place_text(rec)}."
|
||||
text += (" Download its GPX here." if common.has_line(rec)
|
||||
else " Where to get its GPX.")
|
||||
return text if len(text) <= 300 else text[:297].rsplit(" ", 1)[0] + "…"
|
||||
|
||||
+25
-11
@@ -33,8 +33,8 @@ ALL_CANADA = "all provinces and territories"
|
||||
# (label, meaning). Meanings follow docs/schema.md and README.md.
|
||||
TIERS = {
|
||||
"national": ("National Scenic Trail", "A United States National Scenic Trail"),
|
||||
"regional": ("Regional", "A long trail of 80 km (50 mi) or more"),
|
||||
"short": ("Short", "A well-known multi-day trail of 60 to 80 km"),
|
||||
"regional": ("Regional", "A long trail of 50 miles (80 km) or more"),
|
||||
"short": ("Short", "A well-known multi-day trail of 37 to 50 miles (60 to 80 km)"),
|
||||
"deferred": ("Deferred", "Listed, but something about it is not settled; the record's note says what"),
|
||||
"candidate": ("Candidate", "Listing not yet decided"),
|
||||
}
|
||||
@@ -152,6 +152,10 @@ def km_to_mi(km):
|
||||
return km / KM_PER_MI
|
||||
|
||||
|
||||
def m_to_ft(m):
|
||||
return m / M_PER_FT
|
||||
|
||||
|
||||
def fmt_percent(p):
|
||||
"""-2.5 -> "−2.5%" (true minus sign), 0.9 -> "+0.9%", 0 -> "0.0%"."""
|
||||
if p == 0:
|
||||
@@ -169,17 +173,27 @@ def fmt_bytes(n):
|
||||
|
||||
|
||||
def length(km, style="inline", mi=None, measured=False):
|
||||
"""A length in both units. The reader's unit preference decides the order (CSS).
|
||||
"""A length in both units. Miles come first unless the reader chose kilometres (CSS).
|
||||
|
||||
style "inline": "1,287 km (800 mi)"; "stack": large first unit over small second.
|
||||
style "inline": "800 mi (1,287 km)"; "stack": large first unit over small second.
|
||||
measured: a measured length, always written with its one decimal ("2.0 km").
|
||||
"""
|
||||
mi = km_to_mi(km) if mi is None else mi
|
||||
km_text = f"{fmt_km1(km) if measured else fmt_km(km)} km"
|
||||
whole = float(km).is_integer() and not measured
|
||||
mi_text = f"{fmt_int(mi)} mi" if whole or mi >= 100 else f"{mi:,.1f} mi"
|
||||
return Markup(f'<span class="len len--{style}"><span class="len__km">{esc(km_text)}</span>'
|
||||
f'<span class="len__mi">{esc(mi_text)}</span></span>')
|
||||
return Markup(f'<span class="len len--{style}"><span class="len__mi">{esc(mi_text)}</span>'
|
||||
f'<span class="len__km">{esc(km_text)}</span></span>')
|
||||
|
||||
|
||||
def distances(kms):
|
||||
"""Several measured distances in both units, as lengths are: "0.0, 12.4 mi" with "0.0, 20.0 km"
|
||||
behind it, the reader's order decided by CSS. Markup."""
|
||||
kms = list(kms)
|
||||
mi = ", ".join(f"{km_to_mi(k):,.1f}" for k in kms) + " mi"
|
||||
km = ", ".join(fmt_km1(k) for k in kms) + " km"
|
||||
return Markup(f'<span class="len len--inline"><span class="len__mi">{esc(mi)}</span>'
|
||||
f'<span class="len__km">{esc(km)}</span></span>')
|
||||
|
||||
|
||||
# Hiker facts ([hike] table) -------------------------------------------------
|
||||
@@ -228,12 +242,12 @@ def fmt_days(days):
|
||||
|
||||
|
||||
def elevation(m, style="inline"):
|
||||
"""An elevation in metres and feet; the reader's unit preference decides the order,
|
||||
with the same len__km / len__mi pair as lengths: "2,025 m (6,644 ft)".
|
||||
"""An elevation in feet and metres; feet come first unless the reader chose metres,
|
||||
with the same len__mi / len__km pair as lengths: "6,644 ft (2,025 m)".
|
||||
style "stack" sets the first unit large over the second, as lengths do."""
|
||||
ft = m / M_PER_FT
|
||||
return Markup(f'<span class="len len--{style}"><span class="len__km">{esc(fmt_int(m))} m</span>'
|
||||
f'<span class="len__mi">{esc(fmt_int(ft))} ft</span></span>')
|
||||
ft = m_to_ft(m)
|
||||
return Markup(f'<span class="len len--{style}"><span class="len__mi">{esc(fmt_int(ft))} ft</span>'
|
||||
f'<span class="len__km">{esc(fmt_int(m))} m</span></span>')
|
||||
|
||||
|
||||
def join_names(names):
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# Old addresses that people may have saved or shared.
|
||||
/lists/under-100-km/ /lists/under-100-miles/ 301
|
||||
/lists/under-100-km /lists/under-100-miles/ 301
|
||||
+21
-21
@@ -77,15 +77,15 @@ def top_part(body):
|
||||
class GlanceTest(unittest.TestCase):
|
||||
def test_computed_rows_without_a_sourced_high_point(self):
|
||||
t = text(glance_of(render(rec_with(elev()))))
|
||||
self.assertIn("High point 2,000 m 6,562 ft Computed from the track.", t)
|
||||
self.assertIn("Low point 500 m 1,640 ft Computed from the track.", t)
|
||||
self.assertIn("High point 6,562 ft 2,000 m Computed from the track.", t)
|
||||
self.assertIn("Low point 1,640 ft 500 m Computed from the track.", t)
|
||||
# descent within a few percent of the climb is not shown
|
||||
self.assertIn("Climb 3,000 m 9,843 ft Computed from the track, walking south to north.", t)
|
||||
self.assertIn("Climb 9,843 ft 3,000 m Computed from the track, walking south to north.", t)
|
||||
self.assertNotIn("Descent", t)
|
||||
|
||||
def test_descent_shown_when_it_differs(self):
|
||||
t = text(glance_of(render(rec_with(elev(descent_m=1000)))))
|
||||
self.assertIn("Descent: 1,000 m 3,281 ft", t)
|
||||
self.assertIn("Descent: 3,281 ft 1,000 m", t)
|
||||
self.assertIn("walking south to north", t)
|
||||
self.assertFalse(elevation.show_descent(elev(ascent_m=1000, descent_m=951)))
|
||||
self.assertTrue(elevation.show_descent(elev(ascent_m=1000, descent_m=949)))
|
||||
@@ -93,11 +93,11 @@ class GlanceTest(unittest.TestCase):
|
||||
def test_sourced_high_point_is_kept(self):
|
||||
rec = rec_with(elev(), {"high_point": "Example Peak", "high_point_m": 2025, "checked": "2026-11-13"})
|
||||
t = text(glance_of(render(rec)))
|
||||
self.assertIn("High point Example Peak 2,025 m 6,644 ft", t)
|
||||
self.assertIn("High point Example Peak 6,644 ft 2,025 m", t)
|
||||
self.assertNotIn("2,000 m", t) # the computed highest does not replace it
|
||||
# the computed low point and climb still appear, marked as computed
|
||||
self.assertIn("Low point 500 m", t)
|
||||
self.assertIn("Climb 3,000 m", t)
|
||||
self.assertIn("Low point 1,640 ft 500 m", t)
|
||||
self.assertIn("Climb 9,843 ft 3,000 m", t)
|
||||
|
||||
def test_sourced_name_without_an_elevation_stays_as_it_was(self):
|
||||
rec = rec_with(elev(), {"high_point": "Example Peak", "checked": "2026-11-13"})
|
||||
@@ -108,13 +108,13 @@ class GlanceTest(unittest.TestCase):
|
||||
def test_sea_level_low_point(self):
|
||||
data = elev(lowest={"m": 0, "lat": 43.0, "lon": -124.0})
|
||||
t = text(glance_of(render(rec_with(data))))
|
||||
self.assertIn("Low point 0 m 0 ft Sea level. Computed from the track.", t)
|
||||
self.assertIn("Low point 0 ft 0 m Sea level. Computed from the track.", t)
|
||||
self.assertIn("low point of sea level", elevation.summary_sentence(data))
|
||||
|
||||
def test_loop_climb_has_no_direction(self):
|
||||
rec = rec_with(elev(), {"shape": "loop", "checked": "2026-11-13"})
|
||||
t = text(glance_of(render(rec)))
|
||||
self.assertIn("Climb 3,000 m 9,843 ft Computed from the track.", t)
|
||||
self.assertIn("Climb 9,843 ft 3,000 m Computed from the track.", t)
|
||||
self.assertNotIn("walking south to north", text(top_part(render(rec))))
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ class CaveatTest(unittest.TestCase):
|
||||
self.assertIn("No profile is drawn", text(body))
|
||||
self.assertIn(f"{parts} in the elevation sampling", text(body))
|
||||
# the figures are still there
|
||||
self.assertIn("Climb 3,000 m", text(glance_of(body)))
|
||||
self.assertIn("Climb 9,843 ft 3,000 m", text(glance_of(body)))
|
||||
|
||||
|
||||
class ProfileTest(unittest.TestCase):
|
||||
@@ -170,8 +170,8 @@ class ProfileTest(unittest.TestCase):
|
||||
|
||||
def test_axes_in_both_units(self):
|
||||
svg = str(elevation.profile_svg(elev()))
|
||||
km = svg[svg.index('<g class="len__km">'):svg.index('<g class="len__mi">')]
|
||||
mi = svg[svg.index('<g class="len__mi">'):]
|
||||
mi = svg[svg.index('<g class="len__mi">'):svg.index('<g class="len__km">')]
|
||||
km = svg[svg.index('<g class="len__km">'):]
|
||||
self.assertIn("Distance along the track (km)", km)
|
||||
self.assertIn("Elevation (m)", km)
|
||||
self.assertIn("2,000", km) # a metre tick reaches the high point
|
||||
@@ -181,15 +181,15 @@ class ProfileTest(unittest.TestCase):
|
||||
# CSS shows one system, by the same data-units preference as lengths
|
||||
with open(os.path.join(WEB, "assets", "style.css"), encoding="utf-8") as f:
|
||||
css = f.read()
|
||||
self.assertIn(".elev-profile .len__mi { display: none; }", css)
|
||||
self.assertIn(':root[data-units="mi"] .elev-profile .len__mi { display: inline; }', css)
|
||||
self.assertIn(':root[data-units="mi"] .elev-profile .len__km { display: none; }', css)
|
||||
self.assertIn(".elev-profile .len__km { display: none; }", css)
|
||||
self.assertIn(':root[data-units="km"] .elev-profile .len__km { display: inline; }', css)
|
||||
self.assertIn(':root[data-units="km"] .elev-profile .len__mi { display: none; }', css)
|
||||
|
||||
def test_text_alternative_states_the_facts(self):
|
||||
svg = str(elevation.profile_svg(elev()))
|
||||
label = html.unescape(re.search(r'aria-label="([^"]*)"', svg).group(1))
|
||||
for want in ("3,000 m (9,843 ft)", "100.0 km (62 mi)", "500 m (1,640 ft)",
|
||||
"2,000 m (6,562 ft)", "walking south to north"):
|
||||
for want in ("9,843 ft (3,000 m)", "62 mi (100.0 km)", "1,640 ft (500 m)",
|
||||
"6,562 ft (2,000 m)", "walking south to north"):
|
||||
self.assertIn(want, label, want)
|
||||
# the same sentence is the visible caption
|
||||
self.assertIn(label, text(render(rec_with(elev()))))
|
||||
@@ -212,10 +212,10 @@ class AboutTest(unittest.TestCase):
|
||||
for want in ("computed from the trail’s track and Example Model",
|
||||
"A point was taken every 30 m along each part of the track",
|
||||
"Example Model credit, as it gives it.",
|
||||
"Highest point on the track 2,000 m", "At 40.00000, -105.00000",
|
||||
"Lowest point on the track 500 m", "Total climb 3,000 m",
|
||||
"Total descent 2,900 m", "Length sampled 100.0 km",
|
||||
"Coverage 1.000", "Parts 2", "Part starts 50.0 km",
|
||||
"Highest point on the track 6,562 ft 2,000 m", "At 40.00000, -105.00000",
|
||||
"Lowest point on the track 1,640 ft 500 m", "Total climb 9,843 ft 3,000 m",
|
||||
"Total descent 9,514 ft 2,900 m", "Length sampled 62.1 mi 100.0 km",
|
||||
"Coverage 1.000", "Parts 2", "Part starts 31.1 mi 50.0 km",
|
||||
"Computed 2026-11-13",
|
||||
"Computed from a public elevation model, not measured on the ground."):
|
||||
self.assertIn(want, t, want)
|
||||
|
||||
+20
-4
@@ -59,7 +59,7 @@ class ExtraPagesTest(unittest.TestCase):
|
||||
|
||||
def test_all_routes_on_routes_page(self):
|
||||
routes = [r for r in self.records if r["derived"]["kind"] == "route"]
|
||||
self.assertEqual(len(routes), 34)
|
||||
self.assertEqual(len(routes), 47)
|
||||
page = read_out("routes/index.html")
|
||||
import html as _html
|
||||
text = _html.unescape(page)
|
||||
@@ -140,6 +140,9 @@ class ExtraPagesTest(unittest.TestCase):
|
||||
scale = re.search(r'<div class="list-head".*?</div>', results, re.S).group(0)
|
||||
self.assertEqual(scale.count('class="len__km"'), 3, rel)
|
||||
self.assertEqual(scale.count('class="len__mi"'), 3, rel)
|
||||
# round in each unit, miles first
|
||||
self.assertIn('<span class="len__mi">100</span><span class="len__km">100</span>', scale)
|
||||
self.assertIn('<span class="len__mi">10,000 mi</span><span class="len__km">10,000 km</span>', scale)
|
||||
for name in ("Length", "Time", "GPX", "Climb"):
|
||||
self.assertIn(name, scale, rel)
|
||||
for col in ("name", "length", "time", "climb"):
|
||||
@@ -182,9 +185,22 @@ class ExtraPagesTest(unittest.TestCase):
|
||||
# the map is in the tool, beside the list it filters
|
||||
main = doc[doc.index('<div class="finder__main">'):]
|
||||
self.assertLess(main.index('data-map="overview"'), main.index('<ol class="entries" id="entries">'))
|
||||
steps = [int(v) for v in re.findall(r'<option value="(\d+)">', form[form.index('id="max"'):form.index("</select>", form.index('id="max"'))])]
|
||||
self.assertGreaterEqual(steps[-1], max(r["length_km"] for r in self.records))
|
||||
self.assertEqual(home.length_steps(self.records)[:11], list(home.LENGTH_STEPS))
|
||||
longest_km = max(r["length_km"] for r in self.records)
|
||||
maxsel = form[form.index('id="max"'):form.index("</select>", form.index('id="max"'))]
|
||||
minsel = form[form.index('id="min"'):form.index("</select>", form.index('id="min"'))]
|
||||
# the steps are round miles, miles first; the top step reaches the longest trail
|
||||
steps = [int(v) for v in re.findall(r'<option value="(\d+)mi">', maxsel)]
|
||||
self.assertGreaterEqual(steps[-1] * words.KM_PER_MI, longest_km)
|
||||
self.assertEqual(steps, home.length_steps(self.records)[1:])
|
||||
self.assertIn("100 mi · 161 km", minsel)
|
||||
self.assertEqual(home.length_steps(self.records)[:11], list(home.LENGTH_STEPS_MI))
|
||||
# a reader who chose kilometres gets round kilometre steps (app.js builds them from data-steps-km)
|
||||
km_steps = home.length_steps(self.records, "km")
|
||||
self.assertEqual(km_steps[:11], list(home.LENGTH_STEPS_KM))
|
||||
self.assertGreaterEqual(km_steps[-1], longest_km)
|
||||
self.assertIn('data-steps-km="' + ",".join(map(str, km_steps)) + '"', form)
|
||||
for n in home.LENGTH_STEPS_MI + home.LENGTH_STEPS_KM:
|
||||
self.assertEqual(n % 5, 0, n)
|
||||
|
||||
def test_logos_page_shows_exactly_the_logo_files(self):
|
||||
page = read_out("logos/index.html")
|
||||
|
||||
@@ -109,12 +109,17 @@ class TimeTest(unittest.TestCase):
|
||||
rec = fake(1, km=300) # 300 km at 20 to 30 km a day: 10 to 15 days
|
||||
self.assertEqual(facets.time_days(rec), (10, 15, True))
|
||||
self.assertEqual(facets.time_text(rec), "About 1 to 2 weeks")
|
||||
self.assertEqual(facets.estimate_note(rec), "Estimated from the length, at 20 to 30 km (12 to 19 mi) a day.")
|
||||
note = facets.estimate_note(rec) # miles first: both in the HTML, CSS orders them
|
||||
self.assertTrue(note.startswith("Estimated from the length, at "))
|
||||
self.assertLess(note.index('<span class="len__mi">12 to 19 mi</span>'),
|
||||
note.index('<span class="len__km">20 to 30 km</span>'))
|
||||
self.assertTrue(note.endswith(" a day."))
|
||||
self.assertEqual(facets.time_band(rec), "two-weeks")
|
||||
# cross-country is slower: 12 to 20 km a day
|
||||
rec = fake(2, km=300, hike={"travel": "mostly-cross-country"})
|
||||
self.assertEqual(facets.time_days(rec), (15, 25, True))
|
||||
self.assertIn("12 to 20 km", facets.estimate_note(rec))
|
||||
self.assertIn("7 to 12 mi", facets.estimate_note(rec))
|
||||
self.assertEqual(facets.time_band(rec), "month")
|
||||
|
||||
def test_every_trail_has_a_time_and_its_label(self):
|
||||
@@ -276,7 +281,7 @@ class BuiltVocabularyTest(unittest.TestCase):
|
||||
n = len(re.findall(r'<li class="entry" ', doc))
|
||||
self.assertEqual(n, len(records.load_records(ROOT)))
|
||||
self.assertIn(f"<strong>{n}</strong> of {n} trails", doc)
|
||||
self.assertIn(f"{n} long-distance trails", doc)
|
||||
self.assertIn(f"{n} trails. Narrow them", doc)
|
||||
|
||||
def test_route_badges_link_to_the_routes_list(self):
|
||||
for rel in ("index.html", "routes/index.html"):
|
||||
|
||||
@@ -87,9 +87,10 @@ class FormatTest(unittest.TestCase):
|
||||
|
||||
def test_elevation_follows_the_unit_toggle(self):
|
||||
e = str(words.elevation(2025))
|
||||
# the same km/mi pair as lengths, so html[data-units] orders metres and feet too
|
||||
# the same mi/km pair as lengths: feet first, and html[data-units="km"] puts metres first
|
||||
self.assertIn('<span class="len__km">2,025 m</span>', e)
|
||||
self.assertIn('<span class="len__mi">6,644 ft</span>', e)
|
||||
self.assertLess(e.index("len__mi"), e.index("len__km"))
|
||||
self.assertIn('class="len len--inline"', e)
|
||||
|
||||
def test_first_sentence(self):
|
||||
@@ -109,7 +110,7 @@ class TrailPageTest(unittest.TestCase):
|
||||
self.assertIn('href="https://trail.example/"', top)
|
||||
self.assertIn("Official site", t)
|
||||
for want in ("Time 5 to 7 months", "Season March to October", "Example Peak",
|
||||
"2,025 m", "6,644 ft", "Shape End to end. South Gate, Arizona to North Gate, Utah",
|
||||
"6,644 ft 2,025 m", "Shape End to end. South Gate, Arizona to North Gate, Utah",
|
||||
"Terrain Forest, Alpine", "Permits A permit is needed for the national park section.",
|
||||
"Not finished. Forty miles are still on roads."):
|
||||
self.assertIn(want, t, want)
|
||||
@@ -134,7 +135,7 @@ class TrailPageTest(unittest.TestCase):
|
||||
for absent in ("Season March", "High point", "Terrain Alpine", "Permits", "Not finished", "Official site"):
|
||||
self.assertNotIn(absent, t, absent)
|
||||
# no summary: the lede is built from the record
|
||||
self.assertIn("A trail of 100 km 62 mi in Arizona, United States.", t)
|
||||
self.assertIn("A trail of 62 mi 100 km in Arizona, United States.", t)
|
||||
about = render(rec)[render(rec).index('<details class="about-data"'):]
|
||||
self.assertIn("The record names no page for these facts.", about)
|
||||
|
||||
@@ -143,11 +144,11 @@ class TrailPageTest(unittest.TestCase):
|
||||
body = render(rec)
|
||||
top = top_part(body)
|
||||
t = text(top)
|
||||
self.assertIn("A trail of 100 km 62 mi in Arizona, United States.", t)
|
||||
self.assertIn("A trail of 62 mi 100 km in Arizona, United States.", t)
|
||||
self.assertIn("Length", t)
|
||||
self.assertIn("Where Arizona , United States", t)
|
||||
# every trail has a time: here estimated from its 100 km, and labelled so
|
||||
self.assertIn("Time About 4 to 5 days Estimated from the length, at 20 to 30 km (12 to 19 mi) a day.", t)
|
||||
self.assertIn("Time About 4 to 5 days Estimated from the length, at 12 to 19 mi 20 to 30 km a day.", t)
|
||||
self.assertIn("Season, terrain and walking are not on file for this trail yet.", t)
|
||||
self.assertNotIn("Where the hiking facts come from", body)
|
||||
# no track: the page says so plainly and points at the source
|
||||
@@ -191,7 +192,7 @@ class TrailPageTest(unittest.TestCase):
|
||||
# the partial warning above the buttons, and in the glance
|
||||
self.assertLess(panel.index("notice--partial"), panel.index('<ul class="downloads">'))
|
||||
self.assertIn("Partial GPX to download here", top)
|
||||
self.assertIn("Track measures 60.0 km of 100 km published", text(top))
|
||||
self.assertIn("Track measures 37.3 mi 60.0 km of 62 mi 100 km published", text(top))
|
||||
|
||||
def test_report_a_problem_stays_in_view(self):
|
||||
top = top_part(render(sample_record("X Trail")))
|
||||
@@ -232,8 +233,8 @@ class ListTest(unittest.TestCase):
|
||||
cases = {
|
||||
"national-scenic-trails": (fake(1, tier="national"), fake(2)),
|
||||
"routes": (route, fake(2)),
|
||||
"longest": (fake(1, km=2000), fake(2, km=1999)),
|
||||
"under-100-km": (fake(1, km=99), fake(2, km=100)),
|
||||
"longest": (fake(1, km=1609.35), fake(2, km=1609.3)),
|
||||
"under-100-miles": (fake(1, km=160.9), fake(2, km=161)),
|
||||
# by Time: stated, or estimated from the length
|
||||
"a-week-or-less": (fake(1, hike={"days": [4, 7]}), fake(2, hike={"days": [20, 35]})),
|
||||
"one-to-two-weeks": (fake(1, km=250), fake(2, km=100)),
|
||||
|
||||
@@ -394,7 +394,7 @@ class RealDocumentsTest(unittest.TestCase):
|
||||
counter = TableCounter()
|
||||
counter.feed(md.render(read_doc("README.md")))
|
||||
counter.close()
|
||||
self.assertEqual(counter.counts, [104, 34])
|
||||
self.assertEqual(counter.counts, [131, 47])
|
||||
|
||||
def test_readme_num_class_present(self):
|
||||
self.assertIn('class="num"', md.render(read_doc("README.md")))
|
||||
|
||||
@@ -90,7 +90,7 @@ class BuiltSiteTest(unittest.TestCase):
|
||||
def test_one_detail_page_per_record(self):
|
||||
found = [d for d in os.listdir(os.path.join(OUT, "trails"))
|
||||
if os.path.isfile(os.path.join(OUT, "trails", d, "index.html"))]
|
||||
self.assertEqual(len(self.records), 138)
|
||||
self.assertEqual(len(self.records), 178)
|
||||
self.assertEqual(sorted(found), sorted(r["id"] for r in self.records))
|
||||
self.assertTrue(os.path.isfile(os.path.join(OUT, "index.html")))
|
||||
|
||||
@@ -175,7 +175,7 @@ class BuiltSiteTest(unittest.TestCase):
|
||||
v = raw.get("verification", {})
|
||||
if raw["source"].get("line_file") and v.get("verified") and abs(v.get("difference_percent", 0)) > 15:
|
||||
expected.add(rec["id"])
|
||||
self.assertEqual(len(expected), 15)
|
||||
self.assertEqual(len(expected), 17)
|
||||
self.assertIn("voyageur", expected)
|
||||
for rec in self.records:
|
||||
page = self.pages[rec["id"]]
|
||||
@@ -186,8 +186,8 @@ class BuiltSiteTest(unittest.TestCase):
|
||||
self.assertLess(panel.index("notice--partial"), panel.index('<ul class="downloads">'), rec["id"])
|
||||
v = rec["verification"]
|
||||
text = page_text(panel[:panel.index('<ul class="downloads">')])
|
||||
self.assertIn(f"measures {v['measured_km']:,.1f} km against a published "
|
||||
f"{rec['length_km']:,} km ({words.fmt_percent(v['difference_percent'])})", text)
|
||||
self.assertIn(f"{v['measured_km']:,.1f} km against a published", text)
|
||||
self.assertIn(f"{rec['length_km']:,} km ({words.fmt_percent(v['difference_percent'])})", text)
|
||||
self.assertIn(re.sub(r"\s+", " ", rec["source"]["length_gap_note"]), text, rec["id"])
|
||||
short = rec["id"] in expected and rec["verification"]["difference_percent"] < 0
|
||||
glance = page[page.index('<section class="glance'):page.index("</section>", page.index('<section class="glance'))]
|
||||
@@ -208,7 +208,7 @@ class BuiltSiteTest(unittest.TestCase):
|
||||
self.assertEqual(row.count('class="entry__partial"'), 1 if tid in expected else 0, f"{rel}: {tid}")
|
||||
if tid in expected:
|
||||
rows_seen.add(tid)
|
||||
self.assertRegex(page_text(row), r"Track measures [\d,.]+ km (of|against) [\d,]+ km published")
|
||||
self.assertRegex(page_text(row), r"Track measures [\d,.]+ mi [\d,.]+ km (of|against) [\d,]+ mi [\d,.]+ km published")
|
||||
entries = len(re.findall(r'<li class="entry" ', doc))
|
||||
partial_rows = len(re.findall(r'<li class="entry" [^>]*data-partial="yes"', doc))
|
||||
self.assertEqual(doc.count('class="entry__partial"'), partial_rows, rel)
|
||||
|
||||
@@ -13,10 +13,10 @@ class RecordsTest(unittest.TestCase):
|
||||
cls.recs = records.load_records()
|
||||
|
||||
def test_counts(self):
|
||||
self.assertEqual(len(self.recs), 138)
|
||||
self.assertEqual(sum(r["derived"]["kind"] == "route" for r in self.recs), 34)
|
||||
self.assertEqual(sum(r["derived"]["kind"] == "designated" for r in self.recs), 104)
|
||||
self.assertEqual(sum(r["derived"]["has_line"] for r in self.recs), 85)
|
||||
self.assertEqual(len(self.recs), 178)
|
||||
self.assertEqual(sum(r["derived"]["kind"] == "route" for r in self.recs), 47)
|
||||
self.assertEqual(sum(r["derived"]["kind"] == "designated" for r in self.recs), 131)
|
||||
self.assertEqual(sum(r["derived"]["has_line"] for r in self.recs), 97)
|
||||
|
||||
def test_sorted_by_id(self):
|
||||
ids = [r["id"] for r in self.recs]
|
||||
|
||||
@@ -134,7 +134,7 @@ class SortKeysTest(unittest.TestCase):
|
||||
class ListDefaultsTest(unittest.TestCase):
|
||||
def test_only_four_lists_open_in_another_order(self):
|
||||
special = {lst.key: lst.sort for lst in browse.LISTS if lst.sort != "name"}
|
||||
self.assertEqual(special, {"longest": "length-desc", "under-100-km": "length-asc",
|
||||
self.assertEqual(special, {"longest": "length-desc", "under-100-miles": "length-asc",
|
||||
"a-week-or-less": "time-asc", "one-to-two-weeks": "time-asc"})
|
||||
for lst in browse.LISTS:
|
||||
self.assertIn(lst.sort, facets.SORT_LABEL, lst.key)
|
||||
@@ -143,7 +143,7 @@ class ListDefaultsTest(unittest.TestCase):
|
||||
def test_members_come_in_the_list_order(self):
|
||||
recs = [make("short", "Short", km=3000), make("long", "Long", km=5000), make("mid", "Mid", km=100)]
|
||||
self.assertEqual(ids(browse.members(browse.by_key("longest"), recs)), ["long", "short"])
|
||||
self.assertEqual(ids(browse.members(browse.by_key("under-100-km"),
|
||||
self.assertEqual(ids(browse.members(browse.by_key("under-100-miles"),
|
||||
[make("a", "A", km=90), make("b", "B", km=10)])), ["b", "a"])
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
"""Miles and feet come first, everywhere, until a reader chooses kilometres and metres.
|
||||
|
||||
These read the markup writers, the stylesheet and prefs.js; they do not need the built site.
|
||||
"""
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
WEB = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, WEB)
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
from olt import browse, home, words # noqa: E402
|
||||
from test_hike import fake, render, top_part # noqa: E402
|
||||
|
||||
|
||||
def read(*parts):
|
||||
with open(os.path.join(WEB, *parts), encoding="utf-8") as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
class DefaultOrderTest(unittest.TestCase):
|
||||
def test_lengths_and_elevations_are_written_miles_and_feet_first(self):
|
||||
for html_ in (words.length(1287), words.length(1287, "stack"), words.length(2.0, measured=True),
|
||||
words.elevation(2025)):
|
||||
self.assertLess(html_.index("len__mi"), html_.index("len__km"))
|
||||
|
||||
def test_trail_page_at_a_glance_reads_miles_first(self):
|
||||
top = top_part(render(fake(1, km=100)))
|
||||
self.assertLess(top.index('<span class="len__mi">62 mi</span>'),
|
||||
top.index('<span class="len__km">100 km</span>'))
|
||||
|
||||
def test_list_row_reads_miles_first(self):
|
||||
row = home.entry(fake(1, km=100))
|
||||
self.assertLess(row.index('<span class="len__mi">62 mi</span>'),
|
||||
row.index('<span class="len__km">100 km</span>'))
|
||||
self.assertIn('data-km="100"', row) # sorting and filtering stay in kilometres
|
||||
|
||||
def test_footer_switch_lists_miles_first_and_selects_it(self):
|
||||
src = read("olt", "layout.py")
|
||||
self.assertIn('value="mi" checked><span>mi and ft first</span>', src)
|
||||
self.assertLess(src.index("mi and ft first"), src.index("km and m first"))
|
||||
self.assertIn('value="mi" checked><span>mi</span>', home.UNITS_TOGGLE)
|
||||
self.assertLess(home.UNITS_TOGGLE.index(">mi<"), home.UNITS_TOGGLE.index(">km<"))
|
||||
|
||||
|
||||
class StoredChoiceTest(unittest.TestCase):
|
||||
def test_prefs_js_knows_only_km_as_the_opt_in(self):
|
||||
js = read("assets", "prefs.js")
|
||||
self.assertIn("units === 'km'", js)
|
||||
self.assertIn("root.dataset.units = 'km'", js)
|
||||
self.assertNotIn("=== 'mi'", js) # an old stored "mi" is simply miles
|
||||
|
||||
def test_app_js_treats_no_value_as_miles(self):
|
||||
js = read("assets", "app.js")
|
||||
self.assertIn("root.dataset.units !== 'km'", js)
|
||||
self.assertIn("writePref('lh-units', value === 'km' ? 'km' : null)", js)
|
||||
|
||||
def test_css_flips_on_km_and_never_on_mi(self):
|
||||
css = read("assets", "style.css")
|
||||
self.assertNotIn('data-units="mi"', css)
|
||||
self.assertIn(':root[data-units="km"] .len__km { order: -1; }', css)
|
||||
self.assertIn(':root[data-units="km"] .len--short .len__km { display: inline; }', css)
|
||||
self.assertIn(".len--short .len__km { display: none; }", css)
|
||||
self.assertIn(':root[data-units="km"] .list-head__scale .len__km { display: inline; }', css)
|
||||
self.assertIn(':root[data-units="km"] .loglen {', css)
|
||||
# the length strip's ticks sit at 100, 1,000 and 10,000 miles by default, kilometres when chosen
|
||||
self.assertIn("log(100 * 1.609344 / 50)", css)
|
||||
self.assertIn(':root[data-units="km"] .list-head__scale > span:nth-child(1) { inset-inline-start: 10.8%; }', css)
|
||||
|
||||
def test_tick_positions_match_the_strip_scale(self):
|
||||
import math
|
||||
css = read("assets", "style.css")
|
||||
pos = lambda km: math.log(km / 50) / math.log(600) * 100
|
||||
for nth, mi in enumerate(home.SCALE_TICKS, 1):
|
||||
m = re.search(r'\.list-head__scale > span:nth-child\(%d\) \{ inset-inline-start: ([\d.]+)%%' % nth, css)
|
||||
self.assertAlmostEqual(float(m.group(1)), pos(mi * words.KM_PER_MI), delta=0.1)
|
||||
m = re.search(r':root\[data-units="km"\] \.list-head__scale > span:nth-child\(%d\) \{ inset-inline-start: ([\d.]+)%%' % nth, css)
|
||||
self.assertAlmostEqual(float(m.group(1)), pos(mi), delta=0.1)
|
||||
|
||||
|
||||
class LengthListsTest(unittest.TestCase):
|
||||
def test_renamed_lists(self):
|
||||
under = browse.by_key("under-100-miles")
|
||||
self.assertEqual(under.title, "Under 100 miles")
|
||||
self.assertEqual(browse.path(under), "/lists/under-100-miles/")
|
||||
self.assertNotIn("under-100-km", [lst.key for lst in browse.LISTS])
|
||||
self.assertIn("100 miles (161 km)", under.blurb)
|
||||
longest = browse.by_key("longest")
|
||||
self.assertIn("1,000 miles (1,609 km) or more", longest.blurb)
|
||||
|
||||
def test_membership_is_by_the_mile_figure(self):
|
||||
under, longest = browse.by_key("under-100-miles"), browse.by_key("longest")
|
||||
edge = 100 * words.KM_PER_MI
|
||||
self.assertTrue(under.test(fake(1, km=edge - 0.01)))
|
||||
self.assertFalse(under.test(fake(1, km=edge)))
|
||||
self.assertTrue(under.test(fake(1, km=120))) # 75 miles: under 100 miles, though over 100 km
|
||||
edge = 1000 * words.KM_PER_MI
|
||||
self.assertTrue(longest.test(fake(1, km=edge)))
|
||||
self.assertFalse(longest.test(fake(1, km=edge - 0.01)))
|
||||
self.assertFalse(longest.test(fake(1, km=1500))) # 932 miles
|
||||
|
||||
def test_the_hide_rule_is_kept(self):
|
||||
self.assertFalse(browse.is_shown(3, 100))
|
||||
self.assertFalse(browse.is_shown(80, 100))
|
||||
self.assertTrue(browse.is_shown(4, 100))
|
||||
|
||||
|
||||
class RoundStepsTest(unittest.TestCase):
|
||||
def test_steps_are_round_in_their_own_unit(self):
|
||||
for unit, steps in (("mi", home.LENGTH_STEPS_MI), ("km", home.LENGTH_STEPS_KM)):
|
||||
self.assertEqual(list(steps), sorted(steps))
|
||||
for n in steps:
|
||||
self.assertEqual(n % 5, 0, (unit, n))
|
||||
recs = [fake(1, km=60), fake(2, km=10945)]
|
||||
self.assertEqual(home.length_steps(recs, "mi")[-1], 8000) # 6,801 miles
|
||||
self.assertEqual(home.length_steps(recs, "km")[-1], 20000) # above 10,945 km
|
||||
self.assertEqual(home.step_value(100, "mi"), "100mi")
|
||||
self.assertEqual(home.step_label(100, "mi"), "100 mi · 161 km")
|
||||
self.assertEqual(home.step_label(100, "km"), "100 km · 62 mi")
|
||||
|
||||
def test_filter_script_reads_steps_in_both_units(self):
|
||||
js = read("assets", "app.js")
|
||||
self.assertIn("(mi|km)", js)
|
||||
self.assertIn("data-steps-' + unit", js)
|
||||
self.assertIn("dataset.km", js) # rows are still compared in kilometres
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user