diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 6091570..2f08c56 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -50,8 +50,8 @@ jobs: with: python-version: "3.12" # Standard library only: no packages to install, and no ImageMagick. - # web/tools/make_thumbs.py is a manual tool; web/thumbs/ is committed - # and the build only copies those thumbnails (see web/olt/thumbs.py). + # web/tools/make_thumbs.py and make_cards.py are manual tools; web/thumbs/ and + # web/cards/ are committed and the build only copies them (web/olt/thumbs.py, cards.py). - run: python3 -m unittest discover -s web/tests - run: python3 web/build.py --out _site diff --git a/CHANGELOG.md b/CHANGELOG.md index 43fce6e..9cc1288 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,22 @@ # Changelog +## 2026-11-16 - Search visibility: titles, descriptions, headings and links between trails + +- Every trail page has a title in the words people search with: the name hikers use, the abbreviation, the length in miles and what the page offers, for example "Appalachian Trail (AT): 2,198 miles, map and GPX". "GPX" appears only on a page that has a GPX download, and "map" only on a page with a track. A route says it is a route. Pieces are dropped in a fixed order (the kilometres, a route's author, "map", the abbreviation, then "GPX") until the whole title fits in 65 characters. Five trails with very long names are over that, because the name alone is. +- A new optional record field, `common_name`, holds the name hikers use where it differs from `name`, such as "Appalachian Trail" for "Appalachian National Scenic Trail". 13 records have one, each given only where the trail's holder or author uses that name on a page, and that page is the basis in the record's history entry. The trail page's heading shows the common name, with the recorded name under it as "Full name", and the search box finds it. `tools/validate.py` checks the field and `docs/schema.md` describes it. +- Trail descriptions are built from the record: the kind, the length in miles and kilometres, the states or provinces, the usual time where a source states one, then the first sentence of the summary, in at most 155 characters. The stock "Download its GPX here." sentence is gone. +- Place pages are titled for what people search, such as "Long Trails in Colorado: 4 Trails and 6 Routes", and each list says what it is, such as "Loop Hiking Trails: 32 Long Trail Loops". Their descriptions add the count, the shortest and the longest. The home page and the About, Sources, Logos, Data, Record schema, Changelog and left-out pages have their own titles and descriptions too, and no two pages share a description. +- The place and list pages no longer jump from the main heading to third-level headings. +- On the Considered and left out page, the introduction is now spaced from the first group, with the same short space above it as the other list pages. +- Trails link to each other. The foot of each trail page now offers similar trails (close in length, alike in terrain and shape), trails whose own words name this one or share its name, and the longest trails in its state, as before. Every trail is now listed on at least three other trails' pages; 68 were on none. On a trail page, the terrain, a loop, a cross-country walk, and a length or a time that puts the trail in a list now link to that list, and each place page names the lists that hold trails there. +- Every trail page now carries structured data (JSON-LD) built from its record: a `Place` that is also a `TouristAttraction` (schema.org has no type for a trail), with the abbreviation and common name as alternate names, the states, the extent of the track, the official page and the OpenStreetMap relation as `sameAs`, the published length in miles and kilometres, the usual time, the highest point, and the track files with their licence. A route says who its author is. The page's `dateModified` is the newest of its check dates and its history, never the build date. Nothing is marked up that the record does not hold: no rating, review, price or opening hours. +- Every page with a breadcrumb has a `BreadcrumbList` read from the breadcrumb it shows. Place and list pages have a `CollectionPage` with an `ItemList` of their trails. The home page has `WebSite` and `Organization`, which hold only what `web/site.toml` holds. The `Dataset` is now on the data page, and is fuller: creator, keywords, spatial and temporal coverage, date modified, version, the variables, how they are measured, and each download with its format. +- Each trail has its own social card, 1200 by 630 pixels, with its name, length, places and the outline of its track. They are drawn by `web/tools/make_cards.py` and committed in `web/cards/`, as the logo thumbnails are, so the site build stays standard library only. Every page also says what its card shows. +- The sitemap gives each page a `` from the data: a trail's newest check or history date, a list or place page's newest trail, the changelog's newest entry. A page with no date of its own has none. +- The 404 page asks not to be indexed. The raw files under `/trails/` (`trail.toml`, `release.txt`, `map.json`, `sketch.json`, the GeoJSON and the GPX) carry `X-Robots-Tag: noindex`, so a trail's page stays the one result for it. The bulk downloads under `/data/` stay indexable. +- New: an Atom feed of this changelog at `/feed.xml`, linked from every page; links from the data page to the JSON and CSV; a `favicon.ico`; and `/llms.txt`, a plain list of the bulk files, the per-trail file names and the licences. +- No trail's facts changed except the added common names. + ## 2026-11-16 - A monthly refresh process for the whole dataset - The monthly refresh is now written down and can be started with one command. An agent follows the runbook in `.claude/skills/refresh-trails/` (start it with `/refresh-trails`, or `/refresh-trails light` to verify and re-check only). It verifies every record against the pages it cites, re-checks `left-out.toml` and its `waiting` entries, searches for missing trails and routes by region, looks at tracks and emblems, has every proposed change reviewed by a second reader who opens the cited pages, and stops for the maintainer's ruling on borderline trails before anything is applied. diff --git a/appalachian/trail.toml b/appalachian/trail.toml index 0fd093d..c38a52c 100644 --- a/appalachian/trail.toml +++ b/appalachian/trail.toml @@ -2,6 +2,7 @@ id = "appalachian" name = "Appalachian National Scenic Trail" +common_name = "Appalachian Trail" short_name = "AT" short_name_url = "https://www.nps.gov/appa/index.htm" country = "US" @@ -115,3 +116,12 @@ basis = "The emblem is shown by its holder or by the managing agency on the page basis_url = "https://upload.wikimedia.org/wikipedia/commons/2/24/Appalachian_Trail_Marker_Logo.svg" asked_by = "the dataset's own check" outcome = "applied" + +[[history]] +date = "2026-11-16" +change = "The name hikers use, Appalachian Trail, was added as the common name. The recorded name is unchanged." +fields = ["common_name"] +basis = "The National Park Service page for the trail opens its description with 'The Appalachian Trail is a 2,190+ mile long public footpath' and also uses the formal name." +basis_url = "https://www.nps.gov/appa/index.htm" +asked_by = "the dataset's own check" +outcome = "applied" diff --git a/arizona/trail.toml b/arizona/trail.toml index c57ecf9..d31eab0 100644 --- a/arizona/trail.toml +++ b/arizona/trail.toml @@ -2,6 +2,7 @@ id = "arizona" name = "Arizona National Scenic Trail" +common_name = "Arizona Trail" short_name = "AZT" short_name_url = "https://aztrail.org/" country = "US" @@ -95,3 +96,12 @@ fields = ["record"] basis = "The record's own source entry: Arizona Trail Association." asked_by = "the dataset's own check" outcome = "applied" + +[[history]] +date = "2026-11-16" +change = "The name hikers use, Arizona Trail, was added as the common name. The recorded name is unchanged." +fields = ["common_name"] +basis = "The Arizona Trail Association's page is headed 'Welcome to the Arizona Trail' and uses the formal name only in its introduction." +basis_url = "https://aztrail.org/" +asked_by = "the dataset's own check" +outcome = "applied" diff --git a/black-canyon/trail.toml b/black-canyon/trail.toml index 3f837e5..a8b7043 100644 --- a/black-canyon/trail.toml +++ b/black-canyon/trail.toml @@ -2,6 +2,7 @@ id = "black-canyon" name = "Black Canyon National Recreation Trail" +common_name = "Black Canyon Trail" country = "US" regions = ["AZ"] length_km = 129 @@ -90,3 +91,12 @@ fields = ["record"] basis = "The record's own source entry: Bureau of Land Management." asked_by = "the dataset's own check" outcome = "applied" + +[[history]] +date = "2026-11-16" +change = "The name hikers use, Black Canyon Trail, was added as the common name. The recorded name is unchanged." +fields = ["common_name"] +basis = "The Bureau of Land Management page says 'The 80-mile Black Canyon Trail' and uses the formal name in its heading." +basis_url = "https://www.blm.gov/visit/black-canyon-national-recreation-trail" +asked_by = "the dataset's own check" +outcome = "applied" diff --git a/continental-divide/trail.toml b/continental-divide/trail.toml index d883a1d..99f2d95 100644 --- a/continental-divide/trail.toml +++ b/continental-divide/trail.toml @@ -2,6 +2,7 @@ id = "continental-divide" name = "Continental Divide National Scenic Trail" +common_name = "Continental Divide Trail" short_name = "CDT" short_name_url = "https://cdtcoalition.org/" country = "US" @@ -104,3 +105,12 @@ basis = "The emblem is shown by its holder or by the managing agency on the page basis_url = "https://www.fs.usda.gov/sites/default/files/fs_media/fs_document/CDT_ServiceMark_Auth_Guidelines_FINAL_06282021.pdf" asked_by = "the dataset's own check" outcome = "applied" + +[[history]] +date = "2026-11-16" +change = "The name hikers use, Continental Divide Trail, was added as the common name. The recorded name is unchanged." +fields = ["common_name"] +basis = "The Continental Divide Trail Coalition's page says 'the Continental Divide Trail was designated nearly 50 years ago' and gives the formal name as well." +basis_url = "https://cdtcoalition.org/" +asked_by = "the dataset's own check" +outcome = "applied" diff --git a/docs/schema.md b/docs/schema.md index 6da9154..304e001 100644 --- a/docs/schema.md +++ b/docs/schema.md @@ -33,6 +33,7 @@ line_file = "line.geojson" | --- | --- | --- | --- | | `id` | string | Stable identifier. Equals the directory name. Never changes. | `"long-trail"` | | `name` | string | The trail's own name. | `"Long Trail (Vermont)"` | +| `common_name` | string, where present | The name hikers use, where it differs from `name`: `"Appalachian Trail"` for `"Appalachian National Scenic Trail"`. Only where the trail's holder or author (or the agency that manages it) uses that name on a page; the page goes in the `basis_url` of the `[[history]]` entry that adds it. Never made up, and never the same as `name`. The site puts it in the page title, the heading and the search; `name` stays on the page. | `"Appalachian Trail"` | | `short_name` | string, where present | Abbreviation the trail's holder or author uses for it, or, failing that, one in established use among hikers. Never made up: a trail nobody abbreviates has none. Written without full stops (`"AT"`, not `"A.T."`); hyphens and digits stay as the holder writes them. Two trails may truthfully share one, and both show it. | `"LT"` | | `short_name_url` | string, with `short_name` | The page where the abbreviation was seen in use. Required when `short_name` is present; an error without it. An http(s) address. | `"https://www.greenmountainclub.org/"` | | `country` | string | `US` or `CA`. | `"US"` | @@ -212,7 +213,7 @@ Settling a conflict: - fails when an entry that was already there was changed or removed; - prints, for each changed fact, the earlier entries about the same field, and prints `!!` lines where an earlier entry was `declined`, or was asked for by someone other than the dataset's own check. That is where two requests may conflict: read the entry before you change the field again. -**Facts**, which need an entry when they change: `name`, `short_name`, `short_name_url`, `country`, `regions`, `length_km`, `length_note`, `kind`, `tier`, `designation`, `inclusion`; everything in `[source]` except the fields below, which includes the track's source, licence and permission; `osm.relation`; everything in `[shield]` except `note` (the logo); everything in `[hike]` except `summary`, `checked` and the sources (the ends, official page, days, season, terrain, travel, high point, permit, unfinished and caution); `[route]` except `note` (the author and the track policy); `[[guide]]` except the price. A replaced track file counts as a change to `source.line_file`. +**Facts**, which need an entry when they change: `name`, `common_name`, `short_name`, `short_name_url`, `country`, `regions`, `length_km`, `length_note`, `kind`, `tier`, `designation`, `inclusion`; everything in `[source]` except the fields below, which includes the track's source, licence and permission; `osm.relation`; everything in `[shield]` except `note` (the logo); everything in `[hike]` except `summary`, `checked` and the sources (the ends, official page, days, season, terrain, travel, high point, permit, unfinished and caution); `[route]` except `note` (the author and the track policy); `[[guide]]` except the price. A replaced track file counts as a change to `source.line_file`. **Not facts**, which need none: `[[history]]` itself; all of `[verification]`, which the tools refresh; `source.source_checked`, `source.discovery`, `source.format`, `source.crs`, `source.mainline` and `source.length_gap_note`; `hike.summary` (our wording), `hike.checked` and `[[hike.source]]`; `guide.price` and `guide.price_checked`; the notes `osm.note`, `shield.note` and `route.note`; `[[link]]`; `wave` and `wave_note`. A field that is in neither list is a fact. The lists are `FACTS_TEXT` and `NOT_FACTS` in `tools/trail_history.py`, and `python3 tools/check_history.py --facts` prints them. diff --git a/florida/trail.toml b/florida/trail.toml index ae9e0fc..421840f 100644 --- a/florida/trail.toml +++ b/florida/trail.toml @@ -2,6 +2,7 @@ id = "florida" name = "Florida National Scenic Trail" +common_name = "Florida Trail" short_name = "FT" short_name_url = "https://floridatrail.org/explore-the-florida-trail/" country = "US" @@ -110,3 +111,12 @@ basis = "The emblem is shown by its holder or by the managing agency on the page basis_url = "http://apalachee.floridatrail.org/wp-content/uploads/2014/07/FNST-Coalition-Land-Managers-Guide-to-Minimum-Trail-Standards-and-Guidelines-for-the-FNST.pdf" asked_by = "the dataset's own check" outcome = "applied" + +[[history]] +date = "2026-11-16" +change = "The name hikers use, Florida Trail, was added as the common name. The recorded name is unchanged." +fields = ["common_name"] +basis = "The Florida Trail Association's page is headed 'Explore the Florida Trail' and uses the formal name in its text." +basis_url = "https://floridatrail.org/explore-the-florida-trail/" +asked_by = "the dataset's own check" +outcome = "applied" diff --git a/general-george-crook/trail.toml b/general-george-crook/trail.toml index 074eb9b..d4783e5 100644 --- a/general-george-crook/trail.toml +++ b/general-george-crook/trail.toml @@ -2,6 +2,7 @@ id = "general-george-crook" name = "General George Crook National Recreation Trail" +common_name = "General Crook Trail" country = "US" regions = ["AZ"] length_km = 95 @@ -86,3 +87,12 @@ basis = "The pages named in the logo note were searched, and none shows an emble basis_url = "https://www.fs.usda.gov/r03/apache-sitgreaves/recreation/trails/general-crook-trail" asked_by = "the dataset's own check" outcome = "applied" + +[[history]] +date = "2026-11-16" +change = "The name hikers use, General Crook Trail, was added as the common name. The recorded name is unchanged." +fields = ["common_name"] +basis = "The Forest Service page for the trail is headed 'General Crook Trail' and uses that name throughout." +basis_url = "https://www.fs.usda.gov/r03/apache-sitgreaves/recreation/trails/general-crook-trail" +asked_by = "the dataset's own check" +outcome = "applied" diff --git a/ice-age/trail.toml b/ice-age/trail.toml index 7bdc05d..8957462 100644 --- a/ice-age/trail.toml +++ b/ice-age/trail.toml @@ -2,6 +2,7 @@ id = "ice-age" name = "Ice Age National Scenic Trail" +common_name = "Ice Age Trail" short_name = "IAT" short_name_url = "https://www.iceagetrail.org/" country = "US" @@ -103,3 +104,12 @@ basis = "The emblem is shown by its holder or by the managing agency on the page basis_url = "https://www.nps.gov/iatr/planyourvisit/images/Ice-Age-NST-Trailmark.png" asked_by = "the dataset's own check" outcome = "applied" + +[[history]] +date = "2026-11-16" +change = "The name hikers use, Ice Age Trail, was added as the common name. The recorded name is unchanged." +fields = ["common_name"] +basis = "The Ice Age Trail Alliance's page is headed 'About the Ice Age Trail' and uses the formal name in its introduction." +basis_url = "https://www.iceagetrail.org/explore/explore-the-trail/ice-age-trail/" +asked_by = "the dataset's own check" +outcome = "applied" diff --git a/new-england/trail.toml b/new-england/trail.toml index 6807419..50bde90 100644 --- a/new-england/trail.toml +++ b/new-england/trail.toml @@ -2,6 +2,7 @@ id = "new-england" name = "New England National Scenic Trail" +common_name = "New England Trail" short_name = "NET" short_name_url = "https://www.nps.gov/neen/index.htm" country = "US" @@ -96,3 +97,12 @@ fields = ["record"] basis = "The record's own source entry: National Park Service with the Connecticut Forest & Park Association and the Appalachian Mountain Club." asked_by = "the dataset's own check" outcome = "applied" + +[[history]] +date = "2026-11-16" +change = "The name hikers use, New England Trail, was added as the common name. The recorded name is unchanged." +fields = ["common_name"] +basis = "The National Park Service page says 'the New England Trail covers 235 miles' and uses it in its mailing address." +basis_url = "https://www.nps.gov/neen/index.htm" +asked_by = "the dataset's own check" +outcome = "applied" diff --git a/north-country/trail.toml b/north-country/trail.toml index f32a3fb..cda28b5 100644 --- a/north-country/trail.toml +++ b/north-country/trail.toml @@ -2,6 +2,7 @@ id = "north-country" name = "North Country National Scenic Trail" +common_name = "North Country Trail" country = "US" regions = ["ND", "MN", "WI", "MI", "OH", "PA", "NY", "VT"] length_km = 7403 @@ -103,3 +104,12 @@ basis = "The emblem is shown by its holder or by the managing agency on the page basis_url = "https://northcountrytrail.org/files/outreach/NCTA%20Brand%20Standards%20and%20Style%20Guide_2024.pdf" asked_by = "the dataset's own check" outcome = "applied" + +[[history]] +date = "2026-11-16" +change = "The name hikers use, North Country Trail, was added as the common name. The recorded name is unchanged." +fields = ["common_name"] +basis = "The National Park Service page uses 'North Country Trail' in its captions and links, with the formal name in its title." +basis_url = "https://www.nps.gov/noco/index.htm" +asked_by = "the dataset's own check" +outcome = "applied" diff --git a/ouachita/trail.toml b/ouachita/trail.toml index 0b33147..676c0b9 100644 --- a/ouachita/trail.toml +++ b/ouachita/trail.toml @@ -2,6 +2,7 @@ id = "ouachita" name = "Ouachita National Recreation Trail" +common_name = "Ouachita Trail" short_name = "OT" short_name_url = "https://www.friendsoftheouachita.org/about-the-ot" country = "US" @@ -95,3 +96,12 @@ basis = "The emblem is shown by its holder or by the managing agency on the page basis_url = "https://www.friendsoftheouachita.org/wp-content/uploads/2025/04/foot-logo.svg" asked_by = "the dataset's own check" outcome = "applied" + +[[history]] +date = "2026-11-16" +change = "The name hikers use, Ouachita Trail, was added as the common name. The recorded name is unchanged." +fields = ["common_name"] +basis = "The Friends of the Ouachita Trail say: 'The 'Ouachita Trail', as it is more commonly known'." +basis_url = "https://www.friendsoftheouachita.org/about-the-ot" +asked_by = "the dataset's own check" +outcome = "applied" diff --git a/pacific-crest/trail.toml b/pacific-crest/trail.toml index 06f7264..6269358 100644 --- a/pacific-crest/trail.toml +++ b/pacific-crest/trail.toml @@ -2,6 +2,7 @@ id = "pacific-crest" name = "Pacific Crest National Scenic Trail" +common_name = "Pacific Crest Trail" short_name = "PCT" short_name_url = "https://www.pcta.org/" country = "US" @@ -102,3 +103,12 @@ basis = "The emblem is shown by its holder or by the managing agency on the page basis_url = "https://www.fs.usda.gov/sites/nfs/files/trails/pacific-crest-nst/image/PCT%20logo.jpg" asked_by = "the dataset's own check" outcome = "applied" + +[[history]] +date = "2026-11-16" +change = "The name hikers use, Pacific Crest Trail, was added as the common name. The recorded name is unchanged." +fields = ["common_name"] +basis = "The Forest Service page for the trail, which administers it, uses 'Pacific Crest Trail' in its alerts link ('Pacific Crest Trail Closures') beside the formal name." +basis_url = "https://www.fs.usda.gov/trails/pacific-crest-nst" +asked_by = "the dataset's own check" +outcome = "applied" diff --git a/pacific-northwest/trail.toml b/pacific-northwest/trail.toml index 93b8eb8..3d16a92 100644 --- a/pacific-northwest/trail.toml +++ b/pacific-northwest/trail.toml @@ -2,6 +2,7 @@ id = "pacific-northwest" name = "Pacific Northwest National Scenic Trail" +common_name = "Pacific Northwest Trail" short_name = "PNT" short_name_url = "https://www.pnt.org/pnta/know-before-you-go/plan-your-trip/" country = "US" @@ -107,3 +108,12 @@ basis = "The emblem is shown by its holder or by the managing agency on the page basis_url = "https://pnt-prod.s3.amazonaws.com/wp-content/uploads/PNTA-Header.png" asked_by = "the dataset's own check" outcome = "applied" + +[[history]] +date = "2026-11-16" +change = "The name hikers use, Pacific Northwest Trail, was added as the common name. The recorded name is unchanged." +fields = ["common_name"] +basis = "The Pacific Northwest Trail Association's page is titled 'Plan Your Trip on the Pacific Northwest Trail' and gives the formal name in its first paragraph." +basis_url = "https://www.pnt.org/pnta/know-before-you-go/plan-your-trip/" +asked_by = "the dataset's own check" +outcome = "applied" diff --git a/sheltowee-trace/trail.toml b/sheltowee-trace/trail.toml index 486217a..35de622 100644 --- a/sheltowee-trace/trail.toml +++ b/sheltowee-trace/trail.toml @@ -2,6 +2,7 @@ id = "sheltowee-trace" name = "Sheltowee Trace National Recreation Trail" +common_name = "Sheltowee Trace" country = "US" regions = ["KY", "TN"] length_km = 515 @@ -98,3 +99,12 @@ basis = "The emblem is shown by its holder or by the managing agency on the page basis_url = "https://images.squarespace-cdn.com/content/v1/5f656f5d5a92157dd17414ac/1614824980218-WB89JT7X4L2SHLT1LK75/favicon.ico" asked_by = "the dataset's own check" outcome = "applied" + +[[history]] +date = "2026-11-16" +change = "The name hikers use, Sheltowee Trace, was added as the common name. The recorded name is unchanged." +fields = ["common_name"] +basis = "The Sheltowee Trace Association's page says 'The Sheltowee Trace is home to horse riders' under a heading with the formal name." +basis_url = "https://sheltoweetrace.org/trace" +asked_by = "the dataset's own check" +outcome = "applied" diff --git a/tools/tests/test_common_name.py b/tools/tests/test_common_name.py new file mode 100644 index 0000000..6506f86 --- /dev/null +++ b/tools/tests/test_common_name.py @@ -0,0 +1,45 @@ +"""Tests for the common_name check in tools/validate.py: no network, no numpy. + +Run from the repository root: + python3 -m unittest discover tools/tests +""" +import os +import sys +import unittest + +sys.dont_write_bytecode = True +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +import validate as V # noqa: E402 +import trail_history as H # noqa: E402 + + +def check(rec): + errors = [] + V.check_common_name("t", rec, errors) + return errors + + +class CommonNameTest(unittest.TestCase): + def test_none_is_valid(self): + self.assertEqual(check({"name": "Appalachian National Scenic Trail"}), []) + + def test_a_different_name_is_valid(self): + self.assertEqual(check({"name": "Appalachian National Scenic Trail", "common_name": "Appalachian Trail"}), []) + + def test_must_be_a_clean_string(self): + for bad in ("", " ", " Appalachian Trail", "Appalachian Trail ", 7, ["AT"]): + self.assertTrue(check({"name": "x", "common_name": bad}), repr(bad)) + + def test_must_differ_from_name(self): + errors = check({"name": "Long Trail", "common_name": "Long Trail"}) + self.assertEqual(len(errors), 1) + self.assertIn("repeats name", errors[0]) + + def test_is_a_field_that_needs_history(self): + self.assertIn("common_name", H.SCHEMA_FIELDS) + self.assertNotIn("common_name", H.NOT_FACTS) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/trail_history.py b/tools/trail_history.py index 147cc9a..ff0cac5 100644 --- a/tools/trail_history.py +++ b/tools/trail_history.py @@ -18,7 +18,7 @@ URL_RE = re.compile(r"^https?://[^\s/]+\S*$") # Every field a record can have, as the dotted path docs/schema.md uses. A history entry # names these. A table name on its own ("source", "hike.source") names every field in it. _TABLES = { - "": ("id", "name", "short_name", "short_name_url", "country", "regions", "length_km", + "": ("id", "name", "common_name", "short_name", "short_name_url", "country", "regions", "length_km", "length_note", "kind", "tier", "designation", "wave", "wave_note", "inclusion"), "source": ("status", "publisher", "publisher_url", "url", "discovery", "format", "crs", "licence", "licence_text", "permission_quote", "permission_by", @@ -62,7 +62,7 @@ NOT_FACTS = ( "wave", "wave_note", # the dataset's own bookkeeping ) FACTS_TEXT = ( - "name, short_name, short_name_url, country, regions, length_km, length_note, kind, tier, designation, " + "name, common_name, short_name, short_name_url, country, regions, length_km, length_note, kind, tier, designation, " "inclusion; source.* (status, publisher, publisher_url, url, licence, licence_text, " "permission_*, attribution, osm_only, line_source, line_file, line_absent_reason, " "decision, decision_text, redistributable); osm.relation; shield.* except note; " diff --git a/tools/validate.py b/tools/validate.py index 88f7200..48c7986 100644 --- a/tools/validate.py +++ b/tools/validate.py @@ -456,6 +456,19 @@ def check_elevation(tid, tdir, rec, errors): errors.append(f"{where}: source.computed must be a date (YYYY-MM-DD)") +def check_common_name(tid, rec, errors): + """common_name is optional; where present it is the name hikers use, so it is a clean string that differs from name.""" + if "common_name" not in rec: + return + name = rec["common_name"] + if not isinstance(name, str) or not name.strip(): + errors.append(f"{tid}: common_name must be a non-empty string (leave it out when name is the name hikers use)") + elif name != name.strip(): + errors.append(f"{tid}: common_name has a leading or trailing space") + elif name == rec.get("name"): + errors.append(f"{tid}: common_name repeats name (leave it out when they are the same)") + + def check_short_name(tid, rec, errors): """short_name is optional; where present it needs short_name_url, the page where it was seen in use.""" name, url = rec.get("short_name"), rec.get("short_name_url") @@ -692,6 +705,7 @@ def main(): if field not in rec or rec[field] in ("", None, []): errors.append(f"{tid}: missing required field {field}") check_short_name(tid, rec, errors) + check_common_name(tid, rec, errors) if rec.get("id") != tid: errors.append(f"{tid}: id {rec.get('id')!r} does not match directory name") if rec.get("country") not in ("US", "CA"): diff --git a/web/cards/across-utah-route.png b/web/cards/across-utah-route.png new file mode 100644 index 0000000..61805ef Binary files /dev/null and b/web/cards/across-utah-route.png differ diff --git a/web/cards/akshayuk-pass.png b/web/cards/akshayuk-pass.png new file mode 100644 index 0000000..c25fd22 Binary files /dev/null and b/web/cards/akshayuk-pass.png differ diff --git a/web/cards/alexander-mackenzie.png b/web/cards/alexander-mackenzie.png new file mode 100644 index 0000000..4e864a1 Binary files /dev/null and b/web/cards/alexander-mackenzie.png differ diff --git a/web/cards/allegheny-trail.png b/web/cards/allegheny-trail.png new file mode 100644 index 0000000..e5fca8d Binary files /dev/null and b/web/cards/allegheny-trail.png differ diff --git a/web/cards/alpine-trail-7.png b/web/cards/alpine-trail-7.png new file mode 100644 index 0000000..1fba73e Binary files /dev/null and b/web/cards/alpine-trail-7.png differ diff --git a/web/cards/american-discovery-trail.png b/web/cards/american-discovery-trail.png new file mode 100644 index 0000000..15bb859 Binary files /dev/null and b/web/cards/american-discovery-trail.png differ diff --git a/web/cards/appalachian-high-route.png b/web/cards/appalachian-high-route.png new file mode 100644 index 0000000..7c7b5ea Binary files /dev/null and b/web/cards/appalachian-high-route.png differ diff --git a/web/cards/appalachian.png b/web/cards/appalachian.png new file mode 100644 index 0000000..c9d5eda Binary files /dev/null and b/web/cards/appalachian.png differ diff --git a/web/cards/arizona.png b/web/cards/arizona.png new file mode 100644 index 0000000..50f1647 Binary files /dev/null and b/web/cards/arizona.png differ diff --git a/web/cards/avon.png b/web/cards/avon.png new file mode 100644 index 0000000..024c061 Binary files /dev/null and b/web/cards/avon.png differ diff --git a/web/cards/backbone.png b/web/cards/backbone.png new file mode 100644 index 0000000..af35d6f Binary files /dev/null and b/web/cards/backbone.png differ diff --git a/web/cards/baker.png b/web/cards/baker.png new file mode 100644 index 0000000..fca01b8 Binary files /dev/null and b/web/cards/baker.png differ diff --git a/web/cards/bartram.png b/web/cards/bartram.png new file mode 100644 index 0000000..cc1dd6e Binary files /dev/null and b/web/cards/bartram.png differ diff --git a/web/cards/basin-and-range-trail.png b/web/cards/basin-and-range-trail.png new file mode 100644 index 0000000..6869f5e Binary files /dev/null and b/web/cards/basin-and-range-trail.png differ diff --git a/web/cards/batona.png b/web/cards/batona.png new file mode 100644 index 0000000..738f908 Binary files /dev/null and b/web/cards/batona.png differ diff --git a/web/cards/bay-area-ridge.png b/web/cards/bay-area-ridge.png new file mode 100644 index 0000000..b9772de Binary files /dev/null and b/web/cards/bay-area-ridge.png differ diff --git a/web/cards/bay-circuit.png b/web/cards/bay-circuit.png new file mode 100644 index 0000000..4534988 Binary files /dev/null and b/web/cards/bay-circuit.png differ diff --git a/web/cards/beartooth-high-route.png b/web/cards/beartooth-high-route.png new file mode 100644 index 0000000..3bf15bd Binary files /dev/null and b/web/cards/beartooth-high-route.png differ diff --git a/web/cards/benton-mackaye.png b/web/cards/benton-mackaye.png new file mode 100644 index 0000000..ff7a7f1 Binary files /dev/null and b/web/cards/benton-mackaye.png differ diff --git a/web/cards/big-bend-100.png b/web/cards/big-bend-100.png new file mode 100644 index 0000000..dd57a54 Binary files /dev/null and b/web/cards/big-bend-100.png differ diff --git a/web/cards/big-seki-loop.png b/web/cards/big-seki-loop.png new file mode 100644 index 0000000..7be3a96 Binary files /dev/null and b/web/cards/big-seki-loop.png differ diff --git a/web/cards/bigfoot-trail.png b/web/cards/bigfoot-trail.png new file mode 100644 index 0000000..ff57014 Binary files /dev/null and b/web/cards/bigfoot-trail.png differ diff --git a/web/cards/bitterroots-80-mile-route.png b/web/cards/bitterroots-80-mile-route.png new file mode 100644 index 0000000..09695cb Binary files /dev/null and b/web/cards/bitterroots-80-mile-route.png differ diff --git a/web/cards/black-canyon.png b/web/cards/black-canyon.png new file mode 100644 index 0000000..d0d653d Binary files /dev/null and b/web/cards/black-canyon.png differ diff --git a/web/cards/blue-mountains-trail.png b/web/cards/blue-mountains-trail.png new file mode 100644 index 0000000..6cc2006 Binary files /dev/null and b/web/cards/blue-mountains-trail.png differ diff --git a/web/cards/border-route.png b/web/cards/border-route.png new file mode 100644 index 0000000..29350e7 Binary files /dev/null and b/web/cards/border-route.png differ diff --git a/web/cards/boreal-trail.png b/web/cards/boreal-trail.png new file mode 100644 index 0000000..4e00a27 Binary files /dev/null and b/web/cards/boreal-trail.png differ diff --git a/web/cards/boundary-trail-mount-st-helens.png b/web/cards/boundary-trail-mount-st-helens.png new file mode 100644 index 0000000..454f8c5 Binary files /dev/null and b/web/cards/boundary-trail-mount-st-helens.png differ diff --git a/web/cards/boundary-trail-pasayten.png b/web/cards/boundary-trail-pasayten.png new file mode 100644 index 0000000..a6ff9cf Binary files /dev/null and b/web/cards/boundary-trail-pasayten.png differ diff --git a/web/cards/brazeau-loop.png b/web/cards/brazeau-loop.png new file mode 100644 index 0000000..a8b1469 Binary files /dev/null and b/web/cards/brazeau-loop.png differ diff --git a/web/cards/bristol-hills-trail.png b/web/cards/bristol-hills-trail.png new file mode 100644 index 0000000..dd597f6 Binary files /dev/null and b/web/cards/bristol-hills-trail.png differ diff --git a/web/cards/brooks-range-traverse.png b/web/cards/brooks-range-traverse.png new file mode 100644 index 0000000..08fe234 Binary files /dev/null and b/web/cards/brooks-range-traverse.png differ diff --git a/web/cards/bruce-trail.png b/web/cards/bruce-trail.png new file mode 100644 index 0000000..e618554 Binary files /dev/null and b/web/cards/bruce-trail.png differ diff --git a/web/cards/buckeye.png b/web/cards/buckeye.png new file mode 100644 index 0000000..8e1be95 Binary files /dev/null and b/web/cards/buckeye.png differ diff --git a/web/cards/california-coastal.png b/web/cards/california-coastal.png new file mode 100644 index 0000000..a942901 Binary files /dev/null and b/web/cards/california-coastal.png differ diff --git a/web/cards/canol.png b/web/cards/canol.png new file mode 100644 index 0000000..7a951c3 Binary files /dev/null and b/web/cards/canol.png differ diff --git a/web/cards/centennial-sd.png b/web/cards/centennial-sd.png new file mode 100644 index 0000000..ebd0f96 Binary files /dev/null and b/web/cards/centennial-sd.png differ diff --git a/web/cards/chinese-wall-circuit.png b/web/cards/chinese-wall-circuit.png new file mode 100644 index 0000000..3ecb2cb Binary files /dev/null and b/web/cards/chinese-wall-circuit.png differ diff --git a/web/cards/chuck-keiper.png b/web/cards/chuck-keiper.png new file mode 100644 index 0000000..3f92455 Binary files /dev/null and b/web/cards/chuck-keiper.png differ diff --git a/web/cards/circle-of-solitude.png b/web/cards/circle-of-solitude.png new file mode 100644 index 0000000..83ef960 Binary files /dev/null and b/web/cards/circle-of-solitude.png differ diff --git a/web/cards/cohos.png b/web/cards/cohos.png new file mode 100644 index 0000000..96daf0e Binary files /dev/null and b/web/cards/cohos.png differ diff --git a/web/cards/colorado-trail.png b/web/cards/colorado-trail.png new file mode 100644 index 0000000..67af223 Binary files /dev/null and b/web/cards/colorado-trail.png differ diff --git a/web/cards/condor-trail.png b/web/cards/condor-trail.png new file mode 100644 index 0000000..1b69a4c Binary files /dev/null and b/web/cards/condor-trail.png differ diff --git a/web/cards/conestoga-trail.png b/web/cards/conestoga-trail.png new file mode 100644 index 0000000..3339fc2 Binary files /dev/null and b/web/cards/conestoga-trail.png differ diff --git a/web/cards/conservation-trail.png b/web/cards/conservation-trail.png new file mode 100644 index 0000000..ab06824 Binary files /dev/null and b/web/cards/conservation-trail.png differ diff --git a/web/cards/continental-divide.png b/web/cards/continental-divide.png new file mode 100644 index 0000000..4144014 Binary files /dev/null and b/web/cards/continental-divide.png differ diff --git a/web/cards/corvallis-to-the-sea.png b/web/cards/corvallis-to-the-sea.png new file mode 100644 index 0000000..2f65f92 Binary files /dev/null and b/web/cards/corvallis-to-the-sea.png differ diff --git a/web/cards/cottonwood-trail.png b/web/cards/cottonwood-trail.png new file mode 100644 index 0000000..0bb0327 Binary files /dev/null and b/web/cards/cottonwood-trail.png differ diff --git a/web/cards/cranberry-lake-50.png b/web/cards/cranberry-lake-50.png new file mode 100644 index 0000000..77a2c96 Binary files /dev/null and b/web/cards/cranberry-lake-50.png differ diff --git a/web/cards/cross-vermont.png b/web/cards/cross-vermont.png new file mode 100644 index 0000000..9cc256a Binary files /dev/null and b/web/cards/cross-vermont.png differ diff --git a/web/cards/cumberland-trail.png b/web/cards/cumberland-trail.png new file mode 100644 index 0000000..aa7b2e2 Binary files /dev/null and b/web/cards/cumberland-trail.png differ diff --git a/web/cards/dan-zhur-donjek.png b/web/cards/dan-zhur-donjek.png new file mode 100644 index 0000000..b13cf0b Binary files /dev/null and b/web/cards/dan-zhur-donjek.png differ diff --git a/web/cards/deseret-hiking-route.png b/web/cards/deseret-hiking-route.png new file mode 100644 index 0000000..9a08384 Binary files /dev/null and b/web/cards/deseret-hiking-route.png differ diff --git a/web/cards/desert-trail.png b/web/cards/desert-trail.png new file mode 100644 index 0000000..f190083 Binary files /dev/null and b/web/cards/desert-trail.png differ diff --git a/web/cards/desert-winter-thru-hike.png b/web/cards/desert-winter-thru-hike.png new file mode 100644 index 0000000..12afc05 Binary files /dev/null and b/web/cards/desert-winter-thru-hike.png differ diff --git a/web/cards/donut-hole.png b/web/cards/donut-hole.png new file mode 100644 index 0000000..b3babbd Binary files /dev/null and b/web/cards/donut-hole.png differ diff --git a/web/cards/east-beach-trail.png b/web/cards/east-beach-trail.png new file mode 100644 index 0000000..16ed060 Binary files /dev/null and b/web/cards/east-beach-trail.png differ diff --git a/web/cards/east-coast-trail.png b/web/cards/east-coast-trail.png new file mode 100644 index 0000000..c7259a1 Binary files /dev/null and b/web/cards/east-coast-trail.png differ diff --git a/web/cards/eastern-continental-trail.png b/web/cards/eastern-continental-trail.png new file mode 100644 index 0000000..e947cc0 Binary files /dev/null and b/web/cards/eastern-continental-trail.png differ diff --git a/web/cards/eastern-sierra-high-route.png b/web/cards/eastern-sierra-high-route.png new file mode 100644 index 0000000..de99086 Binary files /dev/null and b/web/cards/eastern-sierra-high-route.png differ diff --git a/web/cards/finger-lakes.png b/web/cards/finger-lakes.png new file mode 100644 index 0000000..433735d Binary files /dev/null and b/web/cards/finger-lakes.png differ diff --git a/web/cards/florida.png b/web/cards/florida.png new file mode 100644 index 0000000..9b89230 Binary files /dev/null and b/web/cards/florida.png differ diff --git a/web/cards/foothills.png b/web/cards/foothills.png new file mode 100644 index 0000000..c85da38 Binary files /dev/null and b/web/cards/foothills.png differ diff --git a/web/cards/fremont.png b/web/cards/fremont.png new file mode 100644 index 0000000..b45f166 Binary files /dev/null and b/web/cards/fremont.png differ diff --git a/web/cards/ganaraska.png b/web/cards/ganaraska.png new file mode 100644 index 0000000..e1adfd3 Binary files /dev/null and b/web/cards/ganaraska.png differ diff --git a/web/cards/general-george-crook.png b/web/cards/general-george-crook.png new file mode 100644 index 0000000..7d0fe4c Binary files /dev/null and b/web/cards/general-george-crook.png differ diff --git a/web/cards/georgia-loop.png b/web/cards/georgia-loop.png new file mode 100644 index 0000000..9302d82 Binary files /dev/null and b/web/cards/georgia-loop.png differ diff --git a/web/cards/grand-enchantment.png b/web/cards/grand-enchantment.png new file mode 100644 index 0000000..c810588 Binary files /dev/null and b/web/cards/grand-enchantment.png differ diff --git a/web/cards/grand-moab-route.png b/web/cards/grand-moab-route.png new file mode 100644 index 0000000..68c1f03 Binary files /dev/null and b/web/cards/grand-moab-route.png differ diff --git a/web/cards/grand-valley-trail.png b/web/cards/grand-valley-trail.png new file mode 100644 index 0000000..724bc29 Binary files /dev/null and b/web/cards/grand-valley-trail.png differ diff --git a/web/cards/great-basin-trail.png b/web/cards/great-basin-trail.png new file mode 100644 index 0000000..3edbef7 Binary files /dev/null and b/web/cards/great-basin-trail.png differ diff --git a/web/cards/great-colorado-route.png b/web/cards/great-colorado-route.png new file mode 100644 index 0000000..967efd7 Binary files /dev/null and b/web/cards/great-colorado-route.png differ diff --git a/web/cards/great-divide-trail.png b/web/cards/great-divide-trail.png new file mode 100644 index 0000000..3858b5b Binary files /dev/null and b/web/cards/great-divide-trail.png differ diff --git a/web/cards/great-eastern.png b/web/cards/great-eastern.png new file mode 100644 index 0000000..7d407bb Binary files /dev/null and b/web/cards/great-eastern.png differ diff --git a/web/cards/great-plains-trail.png b/web/cards/great-plains-trail.png new file mode 100644 index 0000000..294881c Binary files /dev/null and b/web/cards/great-plains-trail.png differ diff --git a/web/cards/great-western-divide-loop.png b/web/cards/great-western-divide-loop.png new file mode 100644 index 0000000..5597ccc Binary files /dev/null and b/web/cards/great-western-divide-loop.png differ diff --git a/web/cards/great-western-loop.png b/web/cards/great-western-loop.png new file mode 100644 index 0000000..cdfb15e Binary files /dev/null and b/web/cards/great-western-loop.png differ diff --git a/web/cards/guadalupe-ridge-trail.png b/web/cards/guadalupe-ridge-trail.png new file mode 100644 index 0000000..408ae1e Binary files /dev/null and b/web/cards/guadalupe-ridge-trail.png differ diff --git a/web/cards/hayduke-trail.png b/web/cards/hayduke-trail.png new file mode 100644 index 0000000..08a733c Binary files /dev/null and b/web/cards/hayduke-trail.png differ diff --git a/web/cards/high-country-pathway.png b/web/cards/high-country-pathway.png new file mode 100644 index 0000000..3bf2323 Binary files /dev/null and b/web/cards/high-country-pathway.png differ diff --git a/web/cards/high-sierra.png b/web/cards/high-sierra.png new file mode 100644 index 0000000..e309ba0 Binary files /dev/null and b/web/cards/high-sierra.png differ diff --git a/web/cards/highlands.png b/web/cards/highlands.png new file mode 100644 index 0000000..8d0be6d Binary files /dev/null and b/web/cards/highlands.png differ diff --git a/web/cards/highline.png b/web/cards/highline.png new file mode 100644 index 0000000..d27115c Binary files /dev/null and b/web/cards/highline.png differ diff --git a/web/cards/hoosier-heritage-trail.png b/web/cards/hoosier-heritage-trail.png new file mode 100644 index 0000000..66fd2a9 Binary files /dev/null and b/web/cards/hoosier-heritage-trail.png differ diff --git a/web/cards/horse-shoe.png b/web/cards/horse-shoe.png new file mode 100644 index 0000000..effbe87 Binary files /dev/null and b/web/cards/horse-shoe.png differ diff --git a/web/cards/hot-springs-trail.png b/web/cards/hot-springs-trail.png new file mode 100644 index 0000000..012eaf1 Binary files /dev/null and b/web/cards/hot-springs-trail.png differ diff --git a/web/cards/iat-newfoundland-labrador.png b/web/cards/iat-newfoundland-labrador.png new file mode 100644 index 0000000..9f9a14f Binary files /dev/null and b/web/cards/iat-newfoundland-labrador.png differ diff --git a/web/cards/ice-age.png b/web/cards/ice-age.png new file mode 100644 index 0000000..98ea14d Binary files /dev/null and b/web/cards/ice-age.png differ diff --git a/web/cards/idaho-centennial.png b/web/cards/idaho-centennial.png new file mode 100644 index 0000000..38a6c4a Binary files /dev/null and b/web/cards/idaho-centennial.png differ diff --git a/web/cards/international-appalachian-trail-maine.png b/web/cards/international-appalachian-trail-maine.png new file mode 100644 index 0000000..85c2c51 Binary files /dev/null and b/web/cards/international-appalachian-trail-maine.png differ diff --git a/web/cards/iron-belle-trail.png b/web/cards/iron-belle-trail.png new file mode 100644 index 0000000..66b980a Binary files /dev/null and b/web/cards/iron-belle-trail.png differ diff --git a/web/cards/island-walk.png b/web/cards/island-walk.png new file mode 100644 index 0000000..0d7f2b7 Binary files /dev/null and b/web/cards/island-walk.png differ diff --git a/web/cards/itijjagiaq-trail.png b/web/cards/itijjagiaq-trail.png new file mode 100644 index 0000000..bc484aa Binary files /dev/null and b/web/cards/itijjagiaq-trail.png differ diff --git a/web/cards/john-muir.png b/web/cards/john-muir.png new file mode 100644 index 0000000..ba91343 Binary files /dev/null and b/web/cards/john-muir.png differ diff --git a/web/cards/kekekabic.png b/web/cards/kekekabic.png new file mode 100644 index 0000000..403a6d0 Binary files /dev/null and b/web/cards/kekekabic.png differ diff --git a/web/cards/kings-canyon-high-basin-route.png b/web/cards/kings-canyon-high-basin-route.png new file mode 100644 index 0000000..6f8fa23 Binary files /dev/null and b/web/cards/kings-canyon-high-basin-route.png differ diff --git a/web/cards/knobstone.png b/web/cards/knobstone.png new file mode 100644 index 0000000..5ed0d3b Binary files /dev/null and b/web/cards/knobstone.png differ diff --git a/web/cards/koroc-palmer-loop.png b/web/cards/koroc-palmer-loop.png new file mode 100644 index 0000000..e7f15e6 Binary files /dev/null and b/web/cards/koroc-palmer-loop.png differ diff --git a/web/cards/la-cloche.png b/web/cards/la-cloche.png new file mode 100644 index 0000000..7821508 Binary files /dev/null and b/web/cards/la-cloche.png differ diff --git a/web/cards/laurel-highlands.png b/web/cards/laurel-highlands.png new file mode 100644 index 0000000..e5ebdfe Binary files /dev/null and b/web/cards/laurel-highlands.png differ diff --git a/web/cards/lone-star.png b/web/cards/lone-star.png new file mode 100644 index 0000000..15f92ab Binary files /dev/null and b/web/cards/lone-star.png differ diff --git a/web/cards/long-path.png b/web/cards/long-path.png new file mode 100644 index 0000000..75589b2 Binary files /dev/null and b/web/cards/long-path.png differ diff --git a/web/cards/long-trail.png b/web/cards/long-trail.png new file mode 100644 index 0000000..74852c4 Binary files /dev/null and b/web/cards/long-trail.png differ diff --git a/web/cards/lost-coast.png b/web/cards/lost-coast.png new file mode 100644 index 0000000..88bf13f Binary files /dev/null and b/web/cards/lost-coast.png differ diff --git a/web/cards/lowest-to-highest-route.png b/web/cards/lowest-to-highest-route.png new file mode 100644 index 0000000..26dc9d0 Binary files /dev/null and b/web/cards/lowest-to-highest-route.png differ diff --git a/web/cards/loyalsock.png b/web/cards/loyalsock.png new file mode 100644 index 0000000..57c27dc Binary files /dev/null and b/web/cards/loyalsock.png differ diff --git a/web/cards/maah-daah-hey.png b/web/cards/maah-daah-hey.png new file mode 100644 index 0000000..be44ea3 Binary files /dev/null and b/web/cards/maah-daah-hey.png differ diff --git a/web/cards/maricopa-trail.png b/web/cards/maricopa-trail.png new file mode 100644 index 0000000..1944ba4 Binary files /dev/null and b/web/cards/maricopa-trail.png differ diff --git a/web/cards/mason-dixon.png b/web/cards/mason-dixon.png new file mode 100644 index 0000000..105b615 Binary files /dev/null and b/web/cards/mason-dixon.png differ diff --git a/web/cards/massanutten.png b/web/cards/massanutten.png new file mode 100644 index 0000000..5b3b1a6 Binary files /dev/null and b/web/cards/massanutten.png differ diff --git a/web/cards/mattabesett.png b/web/cards/mattabesett.png new file mode 100644 index 0000000..d5cc0b4 Binary files /dev/null and b/web/cards/mattabesett.png differ diff --git a/web/cards/metacomet-monadnock.png b/web/cards/metacomet-monadnock.png new file mode 100644 index 0000000..044cc0f Binary files /dev/null and b/web/cards/metacomet-monadnock.png differ diff --git a/web/cards/mid-state.png b/web/cards/mid-state.png new file mode 100644 index 0000000..8b93ff8 Binary files /dev/null and b/web/cards/mid-state.png differ diff --git a/web/cards/middle-fork-trail.png b/web/cards/middle-fork-trail.png new file mode 100644 index 0000000..8d4b00f Binary files /dev/null and b/web/cards/middle-fork-trail.png differ diff --git a/web/cards/midland-to-mackinac-trail.png b/web/cards/midland-to-mackinac-trail.png new file mode 100644 index 0000000..fc8fb58 Binary files /dev/null and b/web/cards/midland-to-mackinac-trail.png differ diff --git a/web/cards/midstate-ma.png b/web/cards/midstate-ma.png new file mode 100644 index 0000000..792a1f8 Binary files /dev/null and b/web/cards/midstate-ma.png differ diff --git a/web/cards/mogollon-rim-trail.png b/web/cards/mogollon-rim-trail.png new file mode 100644 index 0000000..ca69e49 Binary files /dev/null and b/web/cards/mogollon-rim-trail.png differ diff --git a/web/cards/mojave-sonoran-trail.png b/web/cards/mojave-sonoran-trail.png new file mode 100644 index 0000000..ec728f0 Binary files /dev/null and b/web/cards/mojave-sonoran-trail.png differ diff --git a/web/cards/monadnock-sunapee.png b/web/cards/monadnock-sunapee.png new file mode 100644 index 0000000..801db6a Binary files /dev/null and b/web/cards/monadnock-sunapee.png differ diff --git a/web/cards/montana-trail.png b/web/cards/montana-trail.png new file mode 100644 index 0000000..81aa686 Binary files /dev/null and b/web/cards/montana-trail.png differ diff --git a/web/cards/mountains-to-sea.png b/web/cards/mountains-to-sea.png new file mode 100644 index 0000000..62e0077 Binary files /dev/null and b/web/cards/mountains-to-sea.png differ diff --git a/web/cards/natchez-trace.png b/web/cards/natchez-trace.png new file mode 100644 index 0000000..264700d Binary files /dev/null and b/web/cards/natchez-trace.png differ diff --git a/web/cards/nepisiguit-migmaq-trail.png b/web/cards/nepisiguit-migmaq-trail.png new file mode 100644 index 0000000..cac9fc9 Binary files /dev/null and b/web/cards/nepisiguit-migmaq-trail.png differ diff --git a/web/cards/new-england.png b/web/cards/new-england.png new file mode 100644 index 0000000..99174af Binary files /dev/null and b/web/cards/new-england.png differ diff --git a/web/cards/north-boundary.png b/web/cards/north-boundary.png new file mode 100644 index 0000000..6d9617e Binary files /dev/null and b/web/cards/north-boundary.png differ diff --git a/web/cards/north-country.png b/web/cards/north-country.png new file mode 100644 index 0000000..003e1cc Binary files /dev/null and b/web/cards/north-country.png differ diff --git a/web/cards/north-south-lbl.png b/web/cards/north-south-lbl.png new file mode 100644 index 0000000..25ac6a8 Binary files /dev/null and b/web/cards/north-south-lbl.png differ diff --git a/web/cards/north-south.png b/web/cards/north-south.png new file mode 100644 index 0000000..1f9a0ff Binary files /dev/null and b/web/cards/north-south.png differ diff --git a/web/cards/north-umpqua.png b/web/cards/north-umpqua.png new file mode 100644 index 0000000..14ef799 Binary files /dev/null and b/web/cards/north-umpqua.png differ diff --git a/web/cards/northern-colorado-trail.png b/web/cards/northern-colorado-trail.png new file mode 100644 index 0000000..44bb7a8 Binary files /dev/null and b/web/cards/northern-colorado-trail.png differ diff --git a/web/cards/northern-new-mexico-loop.png b/web/cards/northern-new-mexico-loop.png new file mode 100644 index 0000000..09e9503 Binary files /dev/null and b/web/cards/northern-new-mexico-loop.png differ diff --git a/web/cards/northville-placid.png b/web/cards/northville-placid.png new file mode 100644 index 0000000..5bd2029 Binary files /dev/null and b/web/cards/northville-placid.png differ diff --git a/web/cards/oak-ridges.png b/web/cards/oak-ridges.png new file mode 100644 index 0000000..bc2b0a3 Binary files /dev/null and b/web/cards/oak-ridges.png differ diff --git a/web/cards/ocean-to-lake.png b/web/cards/ocean-to-lake.png new file mode 100644 index 0000000..963d879 Binary files /dev/null and b/web/cards/ocean-to-lake.png differ diff --git a/web/cards/oregon-coast.png b/web/cards/oregon-coast.png new file mode 100644 index 0000000..1139a97 Binary files /dev/null and b/web/cards/oregon-coast.png differ diff --git a/web/cards/oregon-desert.png b/web/cards/oregon-desert.png new file mode 100644 index 0000000..6b5b3a6 Binary files /dev/null and b/web/cards/oregon-desert.png differ diff --git a/web/cards/ottawa-temiskaming-highland-trail.png b/web/cards/ottawa-temiskaming-highland-trail.png new file mode 100644 index 0000000..29f7605 Binary files /dev/null and b/web/cards/ottawa-temiskaming-highland-trail.png differ diff --git a/web/cards/ouachita.png b/web/cards/ouachita.png new file mode 100644 index 0000000..e711537 Binary files /dev/null and b/web/cards/ouachita.png differ diff --git a/web/cards/ozark-highlands.png b/web/cards/ozark-highlands.png new file mode 100644 index 0000000..f1deb1a Binary files /dev/null and b/web/cards/ozark-highlands.png differ diff --git a/web/cards/ozark-trail.png b/web/cards/ozark-trail.png new file mode 100644 index 0000000..21ac38c Binary files /dev/null and b/web/cards/ozark-trail.png differ diff --git a/web/cards/pacific-crest.png b/web/cards/pacific-crest.png new file mode 100644 index 0000000..9e885a1 Binary files /dev/null and b/web/cards/pacific-crest.png differ diff --git a/web/cards/pacific-northwest.png b/web/cards/pacific-northwest.png new file mode 100644 index 0000000..ac1631b Binary files /dev/null and b/web/cards/pacific-northwest.png differ diff --git a/web/cards/palmetto.png b/web/cards/palmetto.png new file mode 100644 index 0000000..a97827d Binary files /dev/null and b/web/cards/palmetto.png differ diff --git a/web/cards/paumanok-path.png b/web/cards/paumanok-path.png new file mode 100644 index 0000000..708969a Binary files /dev/null and b/web/cards/paumanok-path.png differ diff --git a/web/cards/pfiffner-traverse.png b/web/cards/pfiffner-traverse.png new file mode 100644 index 0000000..726398a Binary files /dev/null and b/web/cards/pfiffner-traverse.png differ diff --git a/web/cards/pinhoti.png b/web/cards/pinhoti.png new file mode 100644 index 0000000..c788792 Binary files /dev/null and b/web/cards/pinhoti.png differ diff --git a/web/cards/potomac-heritage.png b/web/cards/potomac-heritage.png new file mode 100644 index 0000000..1cea7bc Binary files /dev/null and b/web/cards/potomac-heritage.png differ diff --git a/web/cards/prescott-circle.png b/web/cards/prescott-circle.png new file mode 100644 index 0000000..d062cc0 Binary files /dev/null and b/web/cards/prescott-circle.png differ diff --git a/web/cards/pukaskwa-coastal.png b/web/cards/pukaskwa-coastal.png new file mode 100644 index 0000000..6de9861 Binary files /dev/null and b/web/cards/pukaskwa-coastal.png differ diff --git a/web/cards/quehanna.png b/web/cards/quehanna.png new file mode 100644 index 0000000..108c838 Binary files /dev/null and b/web/cards/quehanna.png differ diff --git a/web/cards/rideau-trail.png b/web/cards/rideau-trail.png new file mode 100644 index 0000000..88f0c6f Binary files /dev/null and b/web/cards/rideau-trail.png differ diff --git a/web/cards/ring-the-peak.png b/web/cards/ring-the-peak.png new file mode 100644 index 0000000..17ff289 Binary files /dev/null and b/web/cards/ring-the-peak.png differ diff --git a/web/cards/river-to-river.png b/web/cards/river-to-river.png new file mode 100644 index 0000000..21cca9d Binary files /dev/null and b/web/cards/river-to-river.png differ diff --git a/web/cards/route-in-between.png b/web/cards/route-in-between.png new file mode 100644 index 0000000..562ed85 Binary files /dev/null and b/web/cards/route-in-between.png differ diff --git a/web/cards/san-diego-trans-county-trail.png b/web/cards/san-diego-trans-county-trail.png new file mode 100644 index 0000000..a603fab Binary files /dev/null and b/web/cards/san-diego-trans-county-trail.png differ diff --git a/web/cards/santa-fe-to-taos.png b/web/cards/santa-fe-to-taos.png new file mode 100644 index 0000000..49734fb Binary files /dev/null and b/web/cards/santa-fe-to-taos.png differ diff --git a/web/cards/sawtooth-wilderness-high-route.png b/web/cards/sawtooth-wilderness-high-route.png new file mode 100644 index 0000000..3127741 Binary files /dev/null and b/web/cards/sawtooth-wilderness-high-route.png differ diff --git a/web/cards/sea-to-sea-route.png b/web/cards/sea-to-sea-route.png new file mode 100644 index 0000000..d6c9ac8 Binary files /dev/null and b/web/cards/sea-to-sea-route.png differ diff --git a/web/cards/sentier-international-appalaches.png b/web/cards/sentier-international-appalaches.png new file mode 100644 index 0000000..f3665c3 Binary files /dev/null and b/web/cards/sentier-international-appalaches.png differ diff --git a/web/cards/sentier-national.png b/web/cards/sentier-national.png new file mode 100644 index 0000000..cc303d0 Binary files /dev/null and b/web/cards/sentier-national.png differ diff --git a/web/cards/shawangunk-ridge-trail.png b/web/cards/shawangunk-ridge-trail.png new file mode 100644 index 0000000..8c40e83 Binary files /dev/null and b/web/cards/shawangunk-ridge-trail.png differ diff --git a/web/cards/sheltowee-trace.png b/web/cards/sheltowee-trace.png new file mode 100644 index 0000000..dc2c20c Binary files /dev/null and b/web/cards/sheltowee-trace.png differ diff --git a/web/cards/shenipsit-trail.png b/web/cards/shenipsit-trail.png new file mode 100644 index 0000000..95101bf Binary files /dev/null and b/web/cards/shenipsit-trail.png differ diff --git a/web/cards/sierra-grand-traverse.png b/web/cards/sierra-grand-traverse.png new file mode 100644 index 0000000..2b1d714 Binary files /dev/null and b/web/cards/sierra-grand-traverse.png differ diff --git a/web/cards/sierra-high-route.png b/web/cards/sierra-high-route.png new file mode 100644 index 0000000..15389bd Binary files /dev/null and b/web/cards/sierra-high-route.png differ diff --git a/web/cards/sky-islands-traverse.png b/web/cards/sky-islands-traverse.png new file mode 100644 index 0000000..274d96d Binary files /dev/null and b/web/cards/sky-islands-traverse.png differ diff --git a/web/cards/solitude-loop.png b/web/cards/solitude-loop.png new file mode 100644 index 0000000..0380962 Binary files /dev/null and b/web/cards/solitude-loop.png differ diff --git a/web/cards/south-boundary.png b/web/cards/south-boundary.png new file mode 100644 index 0000000..e66f695 Binary files /dev/null and b/web/cards/south-boundary.png differ diff --git a/web/cards/southeastern-serpentine-trail.png b/web/cards/southeastern-serpentine-trail.png new file mode 100644 index 0000000..f972626 Binary files /dev/null and b/web/cards/southeastern-serpentine-trail.png differ diff --git a/web/cards/southern-sierra-high-route.png b/web/cards/southern-sierra-high-route.png new file mode 100644 index 0000000..d059971 Binary files /dev/null and b/web/cards/southern-sierra-high-route.png differ diff --git a/web/cards/southwestern-horseshoe.png b/web/cards/southwestern-horseshoe.png new file mode 100644 index 0000000..2d47ca7 Binary files /dev/null and b/web/cards/southwestern-horseshoe.png differ diff --git a/web/cards/standing-stone.png b/web/cards/standing-stone.png new file mode 100644 index 0000000..b5bbe8b Binary files /dev/null and b/web/cards/standing-stone.png differ diff --git a/web/cards/stein-valley-traverse.png b/web/cards/stein-valley-traverse.png new file mode 100644 index 0000000..57c11fa Binary files /dev/null and b/web/cards/stein-valley-traverse.png differ diff --git a/web/cards/sunapee-ragged-kearsarge.png b/web/cards/sunapee-ragged-kearsarge.png new file mode 100644 index 0000000..4c028f1 Binary files /dev/null and b/web/cards/sunapee-ragged-kearsarge.png differ diff --git a/web/cards/sunshine-coast.png b/web/cards/sunshine-coast.png new file mode 100644 index 0000000..cc4ec28 Binary files /dev/null and b/web/cards/sunshine-coast.png differ diff --git a/web/cards/superior-hiking.png b/web/cards/superior-hiking.png new file mode 100644 index 0000000..f48583f Binary files /dev/null and b/web/cards/superior-hiking.png differ diff --git a/web/cards/susquehannock.png b/web/cards/susquehannock.png new file mode 100644 index 0000000..93172fb Binary files /dev/null and b/web/cards/susquehannock.png differ diff --git a/web/cards/tahoe-rim.png b/web/cards/tahoe-rim.png new file mode 100644 index 0000000..7b6d10b Binary files /dev/null and b/web/cards/tahoe-rim.png differ diff --git a/web/cards/tahoe-yosemite-trail.png b/web/cards/tahoe-yosemite-trail.png new file mode 100644 index 0000000..a9393d6 Binary files /dev/null and b/web/cards/tahoe-yosemite-trail.png differ diff --git a/web/cards/teton-crest-route.png b/web/cards/teton-crest-route.png new file mode 100644 index 0000000..d54fff4 Binary files /dev/null and b/web/cards/teton-crest-route.png differ diff --git a/web/cards/teton-crest.png b/web/cards/teton-crest.png new file mode 100644 index 0000000..db4ba67 Binary files /dev/null and b/web/cards/teton-crest.png differ diff --git a/web/cards/teton-range-traverse.png b/web/cards/teton-range-traverse.png new file mode 100644 index 0000000..c3f5dbd Binary files /dev/null and b/web/cards/teton-range-traverse.png differ diff --git a/web/cards/thames-valley-trail.png b/web/cards/thames-valley-trail.png new file mode 100644 index 0000000..33ed252 Binary files /dev/null and b/web/cards/thames-valley-trail.png differ diff --git a/web/cards/timberline.png b/web/cards/timberline.png new file mode 100644 index 0000000..3cea7a9 Binary files /dev/null and b/web/cards/timberline.png differ diff --git a/web/cards/toiyabe-crest.png b/web/cards/toiyabe-crest.png new file mode 100644 index 0000000..4edc4cd Binary files /dev/null and b/web/cards/toiyabe-crest.png differ diff --git a/web/cards/tonto-trail.png b/web/cards/tonto-trail.png new file mode 100644 index 0000000..37afd76 Binary files /dev/null and b/web/cards/tonto-trail.png differ diff --git a/web/cards/trans-adirondack-route.png b/web/cards/trans-adirondack-route.png new file mode 100644 index 0000000..1b6253d Binary files /dev/null and b/web/cards/trans-adirondack-route.png differ diff --git a/web/cards/traversee-charlevoix.png b/web/cards/traversee-charlevoix.png new file mode 100644 index 0000000..1d7e897 Binary files /dev/null and b/web/cards/traversee-charlevoix.png differ diff --git a/web/cards/tuscarora.png b/web/cards/tuscarora.png new file mode 100644 index 0000000..6ac7005 Binary files /dev/null and b/web/cards/tuscarora.png differ diff --git a/web/cards/uinta-highline.png b/web/cards/uinta-highline.png new file mode 100644 index 0000000..d7cc76d Binary files /dev/null and b/web/cards/uinta-highline.png differ diff --git a/web/cards/vagabond-loop.png b/web/cards/vagabond-loop.png new file mode 100644 index 0000000..e853c56 Binary files /dev/null and b/web/cards/vagabond-loop.png differ diff --git a/web/cards/vancouver-island-backbone.png b/web/cards/vancouver-island-backbone.png new file mode 100644 index 0000000..f5e3a7a Binary files /dev/null and b/web/cards/vancouver-island-backbone.png differ diff --git a/web/cards/vancouver-island.png b/web/cards/vancouver-island.png new file mode 100644 index 0000000..12e7b84 Binary files /dev/null and b/web/cards/vancouver-island.png differ diff --git a/web/cards/voyageur.png b/web/cards/voyageur.png new file mode 100644 index 0000000..bf84826 Binary files /dev/null and b/web/cards/voyageur.png differ diff --git a/web/cards/warrior-trail.png b/web/cards/warrior-trail.png new file mode 100644 index 0000000..1648e91 Binary files /dev/null and b/web/cards/warrior-trail.png differ diff --git a/web/cards/wasatch-traverse.png b/web/cards/wasatch-traverse.png new file mode 100644 index 0000000..e89c020 Binary files /dev/null and b/web/cards/wasatch-traverse.png differ diff --git a/web/cards/waskahegan.png b/web/cards/waskahegan.png new file mode 100644 index 0000000..a1d6b7e Binary files /dev/null and b/web/cards/waskahegan.png differ diff --git a/web/cards/west-coast-trail.png b/web/cards/west-coast-trail.png new file mode 100644 index 0000000..dd7d5f6 Binary files /dev/null and b/web/cards/west-coast-trail.png differ diff --git a/web/cards/western-uplands.png b/web/cards/western-uplands.png new file mode 100644 index 0000000..8e02438 Binary files /dev/null and b/web/cards/western-uplands.png differ diff --git a/web/cards/wind-river-high-route-dixon-wilson.png b/web/cards/wind-river-high-route-dixon-wilson.png new file mode 100644 index 0000000..56bc03a Binary files /dev/null and b/web/cards/wind-river-high-route-dixon-wilson.png differ diff --git a/web/cards/wind-river-high-route-skurka.png b/web/cards/wind-river-high-route-skurka.png new file mode 100644 index 0000000..417c0e0 Binary files /dev/null and b/web/cards/wind-river-high-route-skurka.png differ diff --git a/web/cards/wonderland.png b/web/cards/wonderland.png new file mode 100644 index 0000000..85fc605 Binary files /dev/null and b/web/cards/wonderland.png differ diff --git a/web/cards/wyoming-range.png b/web/cards/wyoming-range.png new file mode 100644 index 0000000..e2e7ee2 Binary files /dev/null and b/web/cards/wyoming-range.png differ diff --git a/web/cards/yosemite-high-route.png b/web/cards/yosemite-high-route.png new file mode 100644 index 0000000..cf81c2e Binary files /dev/null and b/web/cards/yosemite-high-route.png differ diff --git a/web/olt/browse.py b/web/olt/browse.py index 10b2c1e..39f23ca 100644 --- a/web/olt/browse.py +++ b/web/olt/browse.py @@ -37,6 +37,12 @@ class List: # The order the list opens in, a key of facets.SORTS. Name order unless # the list is defined by an order (the longest, the shortest, a week). sort: str = "name" + # The page's before the site name, in the words people search with; {n} is + # the number of trails. Empty: the list's own title with the count. + page_title: str = "" + + def search_title(self, n): + return (self.page_title or f"{self.title}: {{n}} Trails").format(n=n) def _km(mi): @@ -47,39 +53,46 @@ def _band(key): return lambda r: facets.time_band(r) == key +# The terrain as an adjective, for a list's page title ("Coastal Hiking Trails"). +TERRAIN_ADJECTIVE = {"coast": "Coastal", "lakes": "Lake"} + LISTS = ( List("national-scenic-trails", "National Scenic Trails", "The long trails the United States Congress has named National Scenic Trails.", - facets.is_national), + facets.is_national, page_title="National Scenic Trails: {n} Long Hiking Trails"), List("routes", "Routes", facets.ROUTE_DEFINITION, - lambda r: facets.kind(r) == "route"), + lambda r: facets.kind(r) == "route", page_title="Long Hiking Routes by Author: {n} Routes"), List("longest", "The longest", f"Trails of {LONG_MI:,} miles ({_km(LONG_MI)} km) or more.", - lambda r: r["length_km"] >= LONG_KM, sort="length-desc"), + lambda r: r["length_km"] >= LONG_KM, sort="length-desc", + page_title=f"Longest Hiking Trails: {{n}} Trails of {LONG_MI:,}+ Miles"), 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"), + lambda r: r["length_km"] < SHORT_KM, sort="length-asc", + page_title=f"Hiking Trails Under {SHORT_MI} Miles: {{n}} Long Trails"), 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.", - _band("week"), sort="time-asc"), + _band("week"), sort="time-asc", page_title="Long Trails to Hike in a Week or Less: {n} Trails"), List("one-to-two-weeks", "One to two weeks", "Trails that take one to two weeks, as a source states it or as estimated from the length.", - _band("two-weeks"), sort="time-asc"), + _band("two-weeks"), sort="time-asc", page_title="Long Trails to Hike in One to Two Weeks: {n} Trails"), List("loops", "Loops", "Trails that finish where they start.", - lambda r: facets.shape(r) == "loop"), + lambda r: facets.shape(r) == "loop", page_title="Loop Hiking Trails: {n} Long Trail Loops"), List("with-gpx", "With a GPX to download", "Trails with a GPX file of the track on their page.", - facets.gpx_here), + facets.gpx_here, page_title="Long Trails with a GPX to Download: {n} Trails"), List("canada", "In Canada", "Trails in Canada, or crossing into it.", - lambda r: "CA" in common.countries(r)), + lambda r: "CA" in common.countries(r), page_title="Hiking Trails in Canada: {n} Long Trails"), List("united-states", "In the United States", "Trails in the United States, or crossing into it.", - lambda r: "US" in common.countries(r)), + lambda r: "US" in common.countries(r), page_title="Hiking Trails in the United States: {n} Long Trails"), List("off-trail", "Cross-country", "Trails with stretches of walking where there is no trail.", - lambda r: facets.walking(r) in facets.CROSS_COUNTRY), + lambda r: facets.walking(r) in facets.CROSS_COUNTRY, + page_title="Cross-Country Hiking: {n} Long Trails and Routes"), ) + tuple( List(f"terrain-{t}", label, f"Trails with {t} among their main terrain.", - lambda r, t=t: t in facets.terrain(r)) + lambda r, t=t: t in facets.terrain(r), + page_title=f"{TERRAIN_ADJECTIVE.get(t, label)} Hiking Trails: {{n}} Long Trails") for t, label in words.TERRAIN.items() ) diff --git a/web/olt/cards.py b/web/olt/cards.py new file mode 100644 index 0000000..8083389 --- /dev/null +++ b/web/olt/cards.py @@ -0,0 +1,75 @@ +"""Per-trail social cards (1200 x 630 PNG), the image link previews show for a trail page. + +web/cards/<id>.png is made by web/tools/make_cards.py and committed, the way +the logo thumbnails are (olt/thumbs.py): the site build is standard library +only and draws nothing. The pages step copies each card to trails/<id>/card.png. +A trail with no card file falls back to the site card, with a warning. +""" +import hashlib +import os +import shutil +import struct +import sys + +from . import facets, words + +WEB_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +CARD_DIR = os.path.join(WEB_DIR, "cards") +CARD_NAME = "card.png" + + +def prepare(rec, out_dir, card_dir=CARD_DIR): + """Copy the record's card next to its page. Returns (site path, alt text), or ("", "") + when there is none, which leaves the page on the site card.""" + tid = rec["id"] + dest = os.path.join(out_dir, "trails", tid, CARD_NAME) + src = os.path.join(card_dir, f"{tid}.png") + if not os.path.isfile(src): + print(f"warning: {tid}: no card at {os.path.relpath(src, WEB_DIR)}; the page uses the site card " + f"(run web/tools/make_cards.py)", file=sys.stderr) + if os.path.isfile(dest): + os.remove(dest) + return "", "" + os.makedirs(os.path.dirname(dest), exist_ok=True) + shutil.copyfile(src, dest) + return f"/trails/{tid}/{CARD_NAME}", f"{rec['name']}: its track, and its length in miles and kilometres" + + +def card_name(rec): + """The name a card shows: the one hikers use where the record has it.""" + return rec.get("common_name") or rec["name"] + + +def where(rec): + """The places a card shows: up to three names, else a count.""" + names = [facets.place_name(k) for k in facets.place_keys(rec)] + return ", ".join(names) if len(names) <= 3 else f"{len(names)} states and provinces" + + +def lines(rec): + """The three texts a card shows: its name, its length in miles and kilometres, its places.""" + return (card_name(rec), + f"{words.fmt_int(rec['derived']['length_mi'])} miles · {words.fmt_int(rec['length_km'])} km", + where(rec)) + + +def fingerprint(rec): + """A short hash of what a card shows. make_cards.py stores it in the PNG (text chunk + "olt-card"), and a test compares it, so a record that changes shows up as a stale card.""" + return hashlib.sha1("\n".join(lines(rec)).encode("utf-8")).hexdigest()[:12] + + +def stored_fingerprint(path): + """The "olt-card" text chunk of a card file, or "".""" + with open(path, "rb") as f: + data = f.read() + pos = 8 + while pos + 8 <= len(data): + size, kind = struct.unpack(">I4s", data[pos:pos + 8]) + body = data[pos + 8:pos + 8 + size] + if kind == b"tEXt" and body.startswith(b"olt-card\x00"): + return body.split(b"\x00", 1)[1].decode("latin-1") + if kind == b"IEND": + break + pos += 12 + size + return "" diff --git a/web/olt/common.py b/web/olt/common.py index 240973a..41946d5 100644 --- a/web/olt/common.py +++ b/web/olt/common.py @@ -50,6 +50,34 @@ def partial_short_text(rec): f"{words.length(rec['length_km'], mi=rec['derived']['length_mi'])} published") +# A search result shows about this much. The title limit counts the whole title, +# the site name included. +TITLE_LIMIT = 65 +DESCRIPTION_LIMIT = 155 + + +def title_room(site): + """How many characters a page's own title may have, before " · <site name>".""" + return TITLE_LIMIT - len(site.name) - len(" \u00b7 ") + + +def fit_title(options, site): + """The first of options (richest first) that fits title_room; else the last, the shortest.""" + return next((o for o in options if len(o) <= title_room(site)), options[-1]) + + +def plain_name(rec): + """The name hikers use (common_name) where the record has one, else its name. Plain text.""" + return rec.get("common_name") or rec["name"] + + +def cut_at_word(text, limit): + """text if it fits, else cut at a word with an ellipsis, within limit characters.""" + if len(text) <= limit: + return text + return text[:limit - 1].rsplit(" ", 1)[0].rstrip(" ,;:.") + "\u2026" + + def name(rec): """The record's name as HTML text, marked with its language when it is not English (web/site.toml [name_lang], copied to derived.name_lang by pages.py). diff --git a/web/olt/docs.py b/web/olt/docs.py index 5de7540..6e195c8 100644 --- a/web/olt/docs.py +++ b/web/olt/docs.py @@ -215,7 +215,10 @@ def sources_page(records, site, repo_root): f'<p class="page-head__lede">Where the tracks come from, and the terms each source states.</p>' f'</div></header></div></div>{computed}' f'<div class="container section"><div class="prose doc">{doc_html}</div></div>') - return "Sources", "Where each trail track comes from: licences, track sources and source terms.", Markup(body) + n_tracks = sum(1 for r in records if r.get("source", {}).get("line_file")) + description = (f"Where the tracks and facts for the {len(records)} trails come from: {n_tracks} tracks included, " + f"each source's licence and terms, and the credit each asks for.") + return "Sources and Licences for Trail Tracks and Data", common.cut_at_word(description, common.DESCRIPTION_LIMIT), Markup(body) def logos_page(records, site, repo_root): @@ -254,7 +257,10 @@ their own (<code class="raw">no-logo-exists</code>): the pages that would show o {counts["logo-not-found"]} have an emblem, or may have one, but no usable artwork of it was found at a source the dataset allows (<code class="raw">logo-not-found</code>). Each record says in its logo note where an emblem was looked for.</p></div>""" - return "Logos", "Trail logos, their holders, and how a holder can ask for removal.", Markup(body) + n_logos = sum(1 for r in records if "shield" in r["derived"]["files"]) + description = (f"The {n_logos} trail logos shown on {site.name}, who holds each one, " + f"and how a holder can ask for a logo to be removed.") + return "Trail Logos and Their Holders", common.cut_at_word(description, common.DESCRIPTION_LIMIT), Markup(body) BREAD = Markup('<nav class="breadcrumb" aria-label="Breadcrumb"><ol><li><a href="/about/">About</a></li>') @@ -375,7 +381,9 @@ a source page, a map, or a measured track.</p> {contrib} </section> </div></div>""" - return "About", f"What {site.name} is, how trails are chosen, the data and its sources, and how to correct or add a trail.", Markup(body) + description = (f"{n} trails and routes in the United States and Canada: how a trail is chosen, " + f"where the data comes from, and how to correct or add one.") + return "About: How Trails Are Listed and Checked", common.cut_at_word(description, common.DESCRIPTION_LIMIT), Markup(body) def _size(out_dir, relpath): @@ -490,7 +498,9 @@ def data_page(records, site, repo_root, out_dir): <li><a href="/sources/">Sources</a><small>Each source, its terms and the trails that use it</small></li> </ul></div> </div>""" - return "Data", "Bulk downloads, stable per-trail file URLs, the record schema and licences.", Markup(body) + description = (f"Download the records of all {len(records)} trails, and every track that may be shared, " + f"as CSV, JSON, GeoJSON and GPX. The records are public domain.") + return "Trail Data Downloads: CSV, JSON, GeoJSON and GPX", common.cut_at_word(description, common.DESCRIPTION_LIMIT), Markup(body) def schema_page(site, repo_root): @@ -501,7 +511,9 @@ def schema_page(site, repo_root): <header class="titleblock"><div class="titleblock__text"><p class="kicker">Reference</p> <h1>Record schema</h1></div></header></div></div> <div class="container section"><div class="prose doc">{doc_html}</div></div>""" - return "Record schema", "Every field of a trail record (trail.toml) and what it means.", Markup(body) + return ("Trail Record Schema: Every Field of trail.toml", + "What each field of a trail record means, which fields need a source and a history entry, " + "and how the elevation figures are computed.", Markup(body)) def changelog_page(site, repo_root): @@ -512,7 +524,8 @@ def changelog_page(site, repo_root): <header class="titleblock"><div class="titleblock__text"><p class="kicker">Reference</p> <h1>Changelog</h1></div></header></div></div> <div class="container section"><div class="prose doc">{doc_html}</div></div>""" - return "Changelog", "What changed in the dataset, release by release.", Markup(body) + return ("Changelog: What Changed in the Trail Data", + "Trails added, removed and corrected in the dataset, release by release, newest first.", Markup(body)) def copy_licences(out_dir, repo_root): diff --git a/web/olt/feed.py b/web/olt/feed.py new file mode 100644 index 0000000..5fa24c4 --- /dev/null +++ b/web/olt/feed.py @@ -0,0 +1,86 @@ +"""The Atom feed of the changelog: /feed.xml. + +One entry for each dated heading of CHANGELOG.md ("## 2026-11-16 - What changed"), +newest first, as many as FEED_MAX. An entry's date is its heading's date, never +the build date, so the feed changes only when the changelog does. Each entry links +to its heading on /data/changelog/ and carries the section as HTML. + +No author is named: site.toml names none, so the feed's author is the site. +""" +import html +import os +import re + +from . import docs, md + +FEED_MAX = 30 +HEADING = re.compile(r"^(\d{4}-\d{2}-\d{2})\s*[-:–]\s*(.+)$") + + +def entries(text): + """[(date, title, slug, markdown body)] for the changelog's dated sections, in file order.""" + slugs = [slug for level, _, slug in md.headings(text) if level == 2] + out = [] + for (heading, body), slug in zip(md.split_sections(text, level=2), slugs): + m = HEADING.match(heading) + if m: + out.append((m.group(1), m.group(2).strip(), slug, body)) + return out + + +def newest_date(text): + """The newest date in the changelog, or "".""" + return max((e[0] for e in entries(text)), default="") + + +def atom(text, site): + """The Atom document for a changelog's text; "" when the site has no base_url.""" + if not site.base_url: + return "" + base = site.base_url + + def absolute(href): + return base + href if href.startswith("/") else href + + rewrite = docs.make_link_rewrite(site) + + def link_rewrite(href): + target = rewrite(href) + return absolute(target) if target else target + + found = entries(text)[:FEED_MAX] + q = lambda s: html.escape(s, quote=True) # noqa: E731 + rows = [] + for date, title, slug, body in found: + content = md.render(body, heading_offset=2, link_rewrite=link_rewrite) + url = f"{base}/data/changelog/#{slug}" + rows.append( + f" <entry>\n <title>{q(title)}\n {q(url)}\n" + f' \n' + f" {date}T00:00:00Z\n" + f' {q(content)}\n \n') + updated = f"{max((e[0] for e in found), default='1970-01-01')}T00:00:00Z" + return ('\n' + '\n' + f" {q(site.name)}: what changed\n" + f" {q(site.tagline)}\n" + f" {q(base)}/feed.xml\n" + f' \n' + f' \n' + f" {updated}\n" + f" {q(site.name)}\n" + f"{''.join(rows)}\n") + + +def write_feed(out_dir, site, repo_root): + """Write feed.xml from the changelog. Returns its path, or "" when there is no base_url.""" + text = docs.read_doc(repo_root, "CHANGELOG.md") + xml = atom(text, site) + path = os.path.join(out_dir, "feed.xml") + if not xml: + if os.path.isfile(path): + os.remove(path) + return "" + with open(path, "w", encoding="utf-8", newline="\n") as f: + f.write(xml) + return path diff --git a/web/olt/home.py b/web/olt/home.py index 9780328..6b1a6fa 100644 --- a/web/olt/home.py +++ b/web/olt/home.py @@ -135,7 +135,8 @@ def entry(rec, *, level=3, extra="", routes_list=False, hidden=False): """ route = facets.kind(rec) == "route" lo, hi, est = facets.time_days(rec) - search = " ".join([rec["name"], rec.get("short_name", ""), rec["id"], facets.author(rec)]).lower() + search = " ".join([rec["name"], rec.get("common_name", ""), rec.get("short_name", ""), rec["id"], + facets.author(rec)]).lower() abbr = rec.get("short_name", "") abbr_cls = "entry__abbr" if common.shield_url(rec) else "entry__abbr vh" abbr_html = f' {esc(abbr)}' if abbr else "" @@ -409,7 +410,7 @@ def key(official=True): """ -def results(recs=None, *, finder=False, groups=None, routes_list=False, default_sort="name", saved=False): +def results(recs=None, *, finder=False, groups=None, routes_list=False, default_sort="name", saved=False, top=3): """The list of trails, as every page shows it: div.results > head, key, list head, ol.entries. Every list carries the same "Sort by" control. The rows are written in @@ -417,8 +418,11 @@ def results(recs=None, *, finder=False, groups=None, routes_list=False, default_ JavaScript off; app.js reorders in place and keeps ?sort= in the address. finder: the home page's list, driven by the filters (live count, empty state). - groups: [(heading, trails, extra_fn)] to list the trails under level-3 headings; + groups: [(heading, trails, extra_fn)] to list the trails under headings (level `top`); sorting is within each group and the groups keep their order. + top: the heading level of a trail's name where the trails are not in groups (and of a + group's heading where they are; the names then sit one level lower). 3 under a page's + own h2 (the home page); 2 on a page whose h1 is followed directly by the list. extra_fn(rec) gives HTML placed last in each row. routes_list: passed to entry() for the Routes list (see there). saved: the Saved page's list. Every trail's row is written hidden, and @@ -441,11 +445,11 @@ def results(recs=None, *, finder=False, groups=None, routes_list=False, default_ lists = "" every = ' data-every-trail' if finder or saved else "" for heading, items, extra_fn in groups: - level = 4 if heading else 3 + level = top + 1 if heading else top rows = "\n".join(entry(r, level=level, extra=extra_fn(r) if extra_fn else "", routes_list=routes_list, hidden=saved) for r in items) if heading: - lists += f'\n

{heading}

' + lists += f'\n {heading}' list_id = ' id="entries"' if finder else "" lists += f'\n
    \n{rows}\n
' if finder: @@ -586,6 +590,14 @@ def lists_row(records): """ +def description(records): + """The home page's meta description: how many, what each has, and how many have a GPX.""" + n_gpx = sum(1 for r in records if facets.gpx_here(r)) + text = (f"{len(records)} long-distance hiking trails and routes in the US and Canada: length, typical time, " + f"a source for every fact, and a GPX for {n_gpx}.") + return common.cut_at_word(text, common.DESCRIPTION_LIMIT) + + def render(records, site): """The home page body (HTML).""" c = counts(records) @@ -600,7 +612,7 @@ def render(records, site): f'suggest a trail.

') return f"""
-

{esc(site.name)}

+

{esc(site.name)}: long-distance hiking trails of the United States and Canada

Long-distance hiking trails of the United States and Canada.

  • Filters
  • diff --git a/web/olt/layout.py b/web/olt/layout.py index 85f7fb4..496cd9c 100644 --- a/web/olt/layout.py +++ b/web/olt/layout.py @@ -18,7 +18,7 @@ scripts or styles (the Content-Security-Policy forbids them). import json import os -from . import common, site as site_settings +from . import common, seo, site as site_settings from .markup import Markup, attrs, esc, json_block NAV = ( @@ -33,6 +33,8 @@ NAV_PARENT = {"/trails/": "/", "/lists/": "/", "/routes/": "/", "/sources/": "/about/", "/logos/": "/about/", "/data/": "/about/", "/left-out/": "/about/"} +FEED_PATH = "/feed.xml" # the Atom feed of the changelog (olt/feed.py) + FONT_PRELOADS = ( "/assets/fonts/source-serif-4-latin.woff2", "/assets/fonts/ibm-plex-sans-condensed-400-latin.woff2", @@ -159,17 +161,37 @@ def footer(site): def _ld_json_block(obj): + """One JSON-LD script. "<", ">" and "&" are written as \\u escapes, so no text from a + record can close the script element or start a tag inside it.""" text = json.dumps(obj, ensure_ascii=False, separators=(",", ":")) text = text.replace("<", "\\u003c").replace(">", "\\u003e").replace("&", "\\u0026") return Markup(f'') +def structured_data(jsonld, body, path, site, noindex=False): + """The page's JSON-LD as one ', doc, re.S) + + +def nodes_of(doc): + """Every JSON-LD node on a page, flattened out of any @graph.""" + out = [] + for raw in ld_blocks(doc): + obj = json.loads(raw) + out += obj["@graph"] if "@graph" in obj else [obj] + return out + + +def walk(obj): + """Every dict inside a JSON-LD value.""" + if isinstance(obj, dict): + yield obj + for v in obj.values(): + yield from walk(v) + elif isinstance(obj, list): + for v in obj: + yield from walk(v) + + +def meta(doc, key, attr="property"): + m = re.search(rf']*>(.*?)', doc, re.S) + if not m: + return [] + items = [] + for li in re.findall(r"]*>(.*?)", m.group(1), re.S): + href = re.search(r'href="([^"]*)"', li) + items.append((" ".join(html.unescape(re.sub(r"<[^>]+>", "", li)).split()), href.group(1) if href else "")) + return items + + +def setUpModule(): + os.makedirs(os.path.dirname(OUT), exist_ok=True) + subprocess.run([sys.executable, os.path.join(WEB, "build.py"), "--out", OUT], + check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + +class RequiredPropertiesTest(unittest.TestCase): + """The checker itself: it must fail on a node that lacks what its type needs.""" + + def test_missing_properties_are_found(self): + self.assertEqual(missing({"@type": ["Place", "TouristAttraction"], "name": "X", "url": "u", "@id": "i"}), + ["additionalProperty"]) + self.assertEqual(missing({"@type": "Place"}), ["name"]) + self.assertIn("name", missing({"@type": "BreadcrumbList", "itemListElement": []}) + ["name"]) + self.assertEqual(missing({"@type": "BreadcrumbList"}), ["itemListElement"]) + self.assertEqual(missing({"@type": "ListItem", "position": 1, "name": "A"}), ["item"]) + self.assertEqual(missing({"@type": "ListItem", "position": 1, "name": "A", "item": "https://x/"}), []) + self.assertIn("contentUrl", missing({"@type": "DataDownload", "encodingFormat": "text/csv"})) + self.assertTrue(missing({"@type": "Dataset", "name": "n", "description": "too short"})) + + def test_a_trail_without_a_name_would_fail(self): + rec = records.load_record(ROOT, "long-trail") + rec["derived"]["downloads"] = [] + node = seo.place_node(rec, SITE) + self.assertEqual(missing(node), []) + node.pop("additionalProperty") + self.assertEqual(missing(node), ["additionalProperty"]) + + +class JsonLdTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.records = records.load_records(ROOT) + cls.pages = {p: read(p) for p in page_paths()} + + def test_every_block_parses_and_is_escaped(self): + seen = 0 + for path, doc in self.pages.items(): + for raw in ld_blocks(doc): + seen += 1 + obj = json.loads(raw) + self.assertEqual(obj["@context"], "https://schema.org", path) + self.assertNotRegex(raw, r"[<>&]", f"{path}: unescaped character inside JSON-LD") + self.assertGreater(seen, 280) + + def test_blocks_are_data_blocks_the_policy_allows(self): + """application/ld+json is not script: the browser does not run it, so script-src 'self' + covers every page and nothing here needs a looser policy.""" + rules = serve.parse_headers(os.path.join(OUT, "_headers")) + csp = next(v for pat, hs in rules if pat.match("/") for k, v in hs if k.lower() == "content-security-policy") + script_src = re.search(r"script-src ([^;]*)", csp).group(1).split() + self.assertEqual(script_src, ["'self'"]) + self.assertNotIn("unsafe-inline", csp.replace("style-src-attr 'unsafe-inline'", "")) + for path, doc in self.pages.items(): + self.assertNotRegex(doc, r'