Merge the filter bar and navigation work: keep the seasons work's result wherever both resolved the same conflict
This commit is contained in:
commit
34c6ebd1d3
10 files changed
+143
-60
No files matched your search
@@ -10,6 +10,12 @@
|
||||
- An estimate is replaced when a page that states a season is found. The monthly audit searches again for every one, and a monthly check, which works offline and downloads nothing, flags any estimate whose trail's track or location has changed since the season was set.
|
||||
- For contributors: `hike.season_basis` may now be `estimate`, with a `hike.season_method` that ends "Confidence: high.", "Confidence: medium." or "Confidence: low." and one source that cites the climate data; a season is required on every trail, and the validator refuses an estimate that cites an ordinary page. The packet builder and the blind scorer are `tools/season_judge.py`, the reviewers' instruction is `docs/season-judging.md`, and the audit steps are in `docs/audit.md`.
|
||||
|
||||
## 2026-11-20 - The search box and filters on every page, and ways in to the places
|
||||
|
||||
- Every page that lists trails now has the search box and the filters, however few trails it holds. Until now the 48 state and province pages with fewer than ten trails, the small lists and each route author's page showed the rows alone. The filters shown are the ones that have something to offer: a page with two trails offers the choices those two trails differ on, with the number that each choice leaves, and a page with one trail has the search box alone. Nothing is offered that would show no trails.
|
||||
- The Places page now begins with one row of links, visible at every screen size: States and provinces, Parks, Mountain ranges and Wilderness areas, each with its number of pages. They go to the parts of the page that were at the bottom, below sixty states and provinces.
|
||||
- The home page ends with a line under the rows and the map: Browse by park, by mountain range or by wilderness area, each going to its part of the Places page. The first screen is as it was.
|
||||
|
||||
## 2026-11-20 - A Google tag to count visits
|
||||
|
||||
- Every page now loads a Google tag, so that visits can be counted with Google Analytics. The About page no longer says the site has no tracking or analytics.
|
||||
|
||||
@@ -2298,6 +2298,12 @@ td .linklist a { font-weight: 400; }
|
||||
.lists-row li { flex: none; }
|
||||
.lists-row a { min-block-size: 2.75rem; }
|
||||
}
|
||||
/* The Places hub's jump row: one compact line at the very top, States and provinces and each kind of
|
||||
place with its number of pages; it wraps on a phone rather than scrolling. */
|
||||
.places-jump { margin-block-end: var(--space-1); }
|
||||
.places-jump ul { display: flex; flex-wrap: wrap; gap: 0 var(--space-4); padding: 0; list-style: none; font: 600 0.85rem/1.3 var(--font-sans); }
|
||||
.places-jump a { display: inline-flex; align-items: center; min-block-size: 2.25rem; color: var(--link); }
|
||||
.places-jump__n { margin-inline-start: 0.35em; color: var(--ink-2); font-weight: 400; font-variant-numeric: tabular-nums; }
|
||||
.section--finder { padding-block-start: var(--space-4); }
|
||||
.pills { display: flex; flex-wrap: wrap; gap: var(--space-2); }
|
||||
.pills .check { grid-template-columns: auto auto; padding: 0.15rem var(--space-2); border: 1px solid var(--rule-strong); border-radius: 999px; }
|
||||
|
||||
+1
-1
@@ -312,7 +312,7 @@ def author_page(g, records, site, all_pages):
|
||||
+ " · ".join(f'<a href="{esc(path(x))}">{esc(x["name"])}</a> ({len(x["routes"])})' for x in nav_items) + "</nav>") if nav_items else ""
|
||||
more = str(summary.facts(routes, records, by_authors=False)) if n >= 3 else ""
|
||||
briefs = "".join(f'<h3><a href="{esc(common.trail_path(r))}">{esc(common.plain_name(r))}</a></h3>\n{trail.brief(r)}\n' for r in routes)
|
||||
listing = home.results(groups=[(None, routes, regions.route_guides)], routes_list=True, top=2,
|
||||
listing = home.listing(groups=[(None, routes, regions.route_guides)], routes_list=True, top=2,
|
||||
by=lambda r: with_html(g, r, by_name))
|
||||
route_title = "About the route" if n == 1 else "About each route"
|
||||
bio = about_html(g)
|
||||
|
||||
+29
-17
@@ -239,17 +239,13 @@ def entry(rec, *, level=3, extra="", routes_list=False, hidden=False, eager=Fals
|
||||
|
||||
|
||||
# The filters ------------------------------------------------------------------
|
||||
# One bar and one set of panels, on the home page and on every other page that shows a set of at
|
||||
# least FILTER_MIN trails (listing()), and on every park, range and wilderness page whatever its
|
||||
# size (the owner's rule: every set of trails gets the bar). Everything is built from the page's own trails: a facet that
|
||||
# One bar and one set of panels, on the home page and on every other page that shows a set of
|
||||
# trails (listing()), whatever its size (the owner's rule: every set of trails gets the bar). Everything is built from the page's own trails: a facet that
|
||||
# cannot narrow them is left out, and an option none of them has is not written. The numbers written
|
||||
# here are for the whole set; app.js counts again from the rows on the page every time anything
|
||||
# changes, and hides an option that would show nothing (its counting is facetCounts(), which
|
||||
# web/tests/test_filter_counts.py runs under node against counts made here from the records).
|
||||
|
||||
FILTER_MIN = 10
|
||||
|
||||
|
||||
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:
|
||||
@@ -340,7 +336,7 @@ def finder_form(records, c=None, steps=None, where="all", bare_if_empty=False):
|
||||
<label class="field__label" for="where">{facets.WHERE}</label>
|
||||
<select class="select" id="where" name="where">{opts}</select>
|
||||
</div>""")
|
||||
kms = [r["length_km"] for r in records]
|
||||
kms = [r["length_km"] for r in records] or [0]
|
||||
if any(min(kms) < n * words.KM_PER_MI <= max(kms) for n in steps):
|
||||
first.append(f"""<fieldset class="field" data-facet="length">
|
||||
<legend>{facets.LENGTH}</legend>
|
||||
@@ -443,15 +439,13 @@ def finder_form(records, c=None, steps=None, where="all", bare_if_empty=False):
|
||||
</form>"""
|
||||
|
||||
|
||||
def listing(recs=None, *, where="all", groups=None, always=False, **kw):
|
||||
"""The rows of a page that shows a set of trails, with the filter bar over them when the set
|
||||
has at least FILTER_MIN trails (else results() alone); with always, whatever its size (the
|
||||
bar then holds only the filters that have something to offer). where: the Where filter's
|
||||
scope (finder_form). The other arguments are results()'s."""
|
||||
def listing(recs=None, *, where="all", groups=None, **kw):
|
||||
"""The rows of a page that shows a set of trails, with the filter bar over them whatever the size
|
||||
of the set (the bar holds only the filters that have something to offer, and the search box
|
||||
alone where nothing can narrow the set). where: the Where filter's scope (finder_form). The
|
||||
other arguments are results()'s."""
|
||||
trails = [r for g in groups for r in g[1]] if groups is not None else list(recs)
|
||||
if len(trails) < FILTER_MIN and not always:
|
||||
return results(recs, groups=groups, **kw)
|
||||
return Markup(f"""<div class="finder__bar">{finder_form(trails, where=where, bare_if_empty=always)}</div>
|
||||
return Markup(f"""<div class="finder__bar">{finder_form(trails, where=where, bare_if_empty=True)}</div>
|
||||
{results(recs, groups=groups, finder=True, **kw)}""")
|
||||
|
||||
|
||||
@@ -873,8 +867,25 @@ def description(records):
|
||||
return common.cut_at_word(text, common.DESCRIPTION_LIMIT)
|
||||
|
||||
|
||||
def render(records, site, repo_root=""):
|
||||
"""The home page body (HTML). repo_root: where collections.toml names the lists the page shows."""
|
||||
# How the home page's line names each kind of place, and where on the Places hub it goes.
|
||||
PLACE_WAYS_IN = {"park": "park", "range": "mountain range", "wilderness": "wilderness area"}
|
||||
|
||||
|
||||
def places_line(place_kinds):
|
||||
"""The line below the rows that leads to the Places hub's sections: "Browse by park, by mountain
|
||||
range or by wilderness area." for the kinds that have pages (place_kinds: kind keys), else ""."""
|
||||
from . import places # imported here: places.py is the registry, and loads datafiles like this module
|
||||
links = [f'by <a href="/regions/#{places.KINDS[k].segment}">{PLACE_WAYS_IN[k]}</a>'
|
||||
for k in places.KINDS if k in place_kinds]
|
||||
if not links:
|
||||
return ""
|
||||
text = links[0] if len(links) == 1 else ", ".join(links[:-1]) + " or " + links[-1]
|
||||
return f'<p class="finder__foot finder__places">Browse {text}.</p>'
|
||||
|
||||
|
||||
def render(records, site, repo_root="", place_kinds=()):
|
||||
"""The home page body (HTML). repo_root: where collections.toml names the lists the page shows.
|
||||
place_kinds: the kinds of place (olt/places.py) that have pages; the page then ends with a line to them."""
|
||||
c = counts(records)
|
||||
recs = sorted(records, key=sort_name)
|
||||
total = c["total"]
|
||||
@@ -900,6 +911,7 @@ def render(records, site, repo_root=""):
|
||||
{browse_view(listing, overview_map(records, "Map of the trails the filters leave", scope="all"))}
|
||||
<div class="finder__notes">
|
||||
<p class="finder__foot">Not for navigation: tracks vary in quality and some trails are unfinished. Check each trail’s own maps before you go.</p>
|
||||
{places_line(place_kinds)}
|
||||
{contribute}
|
||||
</div>
|
||||
</div>"""
|
||||
+1
-1
@@ -125,7 +125,7 @@ def render_site(records, out_dir, repo_root, site=None):
|
||||
image=card, image_alt=card_alt))
|
||||
dates[path] = seo.modified(rec)
|
||||
pages += 1
|
||||
body = home.render(records, site, repo_root)
|
||||
body = home.render(records, site, repo_root, place_kinds={i["kind"] for i in place_infos.values()})
|
||||
layout.write_page(out_dir, "/", layout.layout("", body, path="/", maps=True, site=site,
|
||||
description=home.description(records),
|
||||
jsonld=seo.home_jsonld(site)))
|
||||
|
||||
@@ -75,7 +75,7 @@ def _kind():
|
||||
kicker=_kicker, crumbs=_crumbs, lede=_lede, where="all", wholly=False,
|
||||
facts_place=lambda info: (_in_name(info), ()), title_options=_title_options,
|
||||
description=_description, box=lambda info: info.get("box"), nav=_nav,
|
||||
in_name=_in_name, phrase=_phrase, always_filters=True)
|
||||
in_name=_in_name, phrase=_phrase)
|
||||
|
||||
|
||||
PARK = _kind()
|
||||
|
||||
+11
-5
@@ -168,6 +168,7 @@ def regions_index_page(records, site, infos=()):
|
||||
place_infos = list(infos.values()) if isinstance(infos, dict) else list(infos or ())
|
||||
blocks = ""
|
||||
jump = []
|
||||
kinds = []
|
||||
for g, name, keys in facets.PLACE_GROUPS:
|
||||
infos = sorted((by_slug[k.lower()] for k in keys if k.lower() in by_slug), key=lambda i: i["name"])
|
||||
if not infos:
|
||||
@@ -200,7 +201,7 @@ def regions_index_page(records, site, infos=()):
|
||||
f'<li><a href="{esc(i["path"])}">{esc(i["name"])}</a>'
|
||||
f'<span class="places__n">{_plural(len(i["records"]))}</span></li>'
|
||||
for i in mine)
|
||||
jump.append(f'<li><a href="#{esc(kind.segment)}">{esc(kind.hub_title)}<span class="lists-row__n">{len(mine)}</span></a></li>')
|
||||
kinds.append(f'<li><a href="#{esc(kind.segment)}">{esc(kind.hub_title)} <span class="places-jump__n">{len(mine)}</span></a></li>')
|
||||
blocks += f"""<section class="places__group" aria-labelledby="{esc(kind.segment)}">
|
||||
<h2 id="{esc(kind.segment)}">{esc(kind.hub_title)}</h2>
|
||||
<ul class="places__list">{rows}</ul>
|
||||
@@ -214,12 +215,18 @@ def regions_index_page(records, site, infos=()):
|
||||
foot = f'\n<div class="container"><p class="places__sum">Places with no listed trail: {links}.</p></div>'
|
||||
n_us = sum(1 for r in records if "US" in common.countries(r))
|
||||
n_ca = sum(1 for r in records if "CA" in common.countries(r))
|
||||
body = f"""<div class="page-head"><div class="container"><header class="titleblock">
|
||||
# One compact row at the very top, whatever the screen: the states and provinces and each kind of
|
||||
# place that has pages, each with its exact number of pages.
|
||||
row = (f'<nav class="places-jump" aria-label="Jump to a kind of place"><ul>'
|
||||
f'<li><a href="#states-and-provinces">States and provinces <span class="places-jump__n">{len(by_slug)}</span></a></li>'
|
||||
f'{"".join(kinds)}</ul></nav>') if kinds else ""
|
||||
body = f"""<div class="page-head"><div class="container">{row}<header class="titleblock">
|
||||
<div class="titleblock__text"><h1>Places</h1>
|
||||
<p class="page-head__lede">The {len(records)} trails by state and province, grouped into parts of the
|
||||
United States ({n_us}) and Canada ({n_ca}). A trail that crosses several states is on each one’s page.{lede_more}</p>
|
||||
</div></header>
|
||||
<nav class="lists-row" aria-label="Jump to a part of the country{" or a kind of place" if place_infos else ""}"><ul>{"".join(jump)}</ul></nav></div></div>
|
||||
<nav class="lists-row" aria-label="Jump to a part of the country"><ul>{"".join(jump)}</ul></nav></div></div>
|
||||
<span id="states-and-provinces"></span>
|
||||
<div class="container section places">{blocks}</div>{foot}"""
|
||||
description = (f"Where the {len(records)} long trails and routes are: {n_us} in the United States and {n_ca} in Canada, "
|
||||
f"by state and province, with the number in each.")
|
||||
@@ -309,7 +316,6 @@ class PageKind:
|
||||
nav: object
|
||||
in_name: object = None
|
||||
phrase: object = None
|
||||
always_filters: bool = False # the filter bar whatever the number of trails
|
||||
|
||||
|
||||
def _state_kicker(info):
|
||||
@@ -433,7 +439,7 @@ def place_page(info, records, site, kind, *, facet_pages=(), place_links=""):
|
||||
</div></header>
|
||||
</div></div>
|
||||
<div class="container section place">
|
||||
{home.browse_view(home.listing(recs, top=2, where=kind.where, wholly=wholly, always=kind.always_filters), home.overview_map(recs, f"Map of the trails {phrase}", place=kind.box(info)),
|
||||
{home.browse_view(home.listing(recs, top=2, where=kind.where, wholly=wholly), home.overview_map(recs, f"Map of the trails {phrase}", place=kind.box(info)),
|
||||
about=f"{summary.facts(recs, records, place=place)}{summary.details(recs)}",
|
||||
about_title=f"About the trails {phrase}")}
|
||||
{nav}{place_links}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"/regions/": "e70a9608ef0ee6a97d0591ad582abff1b165371dee5111e3277df06a53a554e1",
|
||||
"/regions/atlantic-canada/": "6af5c4a79cac82eb0a4342297fd4f6755890e98597a98f219087c56432f06243",
|
||||
"/regions/ca-on/": "12b5726d800090233f082a572cf1472f152552cef8fa5019f49b83e32e337eef",
|
||||
"/regions/central-canada/": "fa6f8bbe466b5978f1edda22371b6aab8546efa567eee0d0405c717e278b8a3e",
|
||||
"/regions/mountain-west/": "c079eb93a55c2279f24083983230057940eb032cb034057c822c52230ce22e05",
|
||||
"/regions/north/": "fdfd201ae1e42b8fd17dd055815d4b06392a8ddb6ac3e72a06f15ec2b333fb56",
|
||||
"/regions/us-co/": "45cb1b92fd22ffc35f82a26fe2c71b66836b0624bf0e195f9c4926dfab6a8900",
|
||||
"/regions/us-co/loops/": "8883c9aac63f100196f9e853d6738a42b8199f1250c10ec34d1d0cfe8c998e7d",
|
||||
"/regions/us-co/with-gpx/": "abc3f7e44cbcbf8d6cce3b5d5065e6e7c085ec5a4033842af8909077f87e1e18",
|
||||
"/regions/": "7430cb0e32ffb89d0bc0bd89c476bccf9fc76e2d84175ebacd7370dc3bb20d1e",
|
||||
"/regions/atlantic-canada/": "5146b4b9d1940a268cfd2345f1eee2263fd6c7e2dfd28adfdffc3fff0e698c93",
|
||||
"/regions/ca-on/": "d4e543c6f163ba188a34444b42c494a3dbbd26c02f2b141339bbc230cd91f84e",
|
||||
"/regions/central-canada/": "d7478ad682d715705770d35cc902c80c40d27719e7f9f5a1d99ec702d3f7a43e",
|
||||
"/regions/mountain-west/": "6151f5a28d366fb48aab7027f08cea6da425201d0e7327780a01dd77cedc7bc7",
|
||||
"/regions/north/": "85ba3ea850c2df690e311cf09257f2548ed888c07c319a01fd30d5e19cdf1fd4",
|
||||
"/regions/us-co/": "97daaf3511578896b222570cba630da2d8ca0571504ce43b3685dbe532e40f56",
|
||||
"/regions/us-co/loops/": "03896834b5369655f7b5f26634b6d23c834b17f1a25b0ec328d44934e20e2dfa",
|
||||
"/regions/us-co/with-gpx/": "d82eace3d70eb9b1ef1346f5a3470199bd6a00e6e104fe661bfeb80199af96b8",
|
||||
"/regions/us-hi/": "1e5681ffbd50e382db7d69528fde602069006bf0cddad494d817369224bd96ad",
|
||||
"/regions/us-ut/": "065bcc01e14eb588dc1b118c466f44474fca0172c30037fb193d83a044624100",
|
||||
"/regions/western-canada/": "91b40d35dd3d1a093d38d01bbfcf1ef536221a69631fc58e46732da81d0582c3"
|
||||
"/regions/us-ut/": "906db4153def35fa5418d0b86dba908fd27396bbc2098978ee169516e1b39785",
|
||||
"/regions/western-canada/": "1b102ed9d47283869fdf8c8d54229d245f2113fd53c7e8ec2ecc118fd4da3b64"
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
"""The filter bar on every page that shows a set of trails, and the numbers beside its choices.
|
||||
|
||||
The bar (olt/home.py listing(), finder_form()) is the home page's, on each list, place and the Routes
|
||||
page whose set has at least home.FILTER_MIN trails, built from that page's own trails. app.js counts
|
||||
page, whatever the number of trails, built from that page's own trails. app.js counts
|
||||
the choices again from the rows on the page every time anything changes (FacetCount, between the
|
||||
facet-counts markers); this file runs that counting under node, on the rows the home page writes,
|
||||
and checks it against counts made here straight from the records. Pages are rendered one at a time;
|
||||
@@ -68,22 +68,36 @@ class WhichPagesHaveTheBarTest(unittest.TestCase):
|
||||
lst = browse.by_key(key)
|
||||
return regions.list_page(lst, self.shown[key], len(self.records), SITE, records=self.records)[2]
|
||||
|
||||
def test_a_list_page_a_place_page_a_part_of_the_country_and_routes_have_it(self):
|
||||
self.assertGreaterEqual(len(self.shown["loops"]), home.FILTER_MIN)
|
||||
self.assertTrue(form_of(self.list_body("loops")))
|
||||
def test_a_list_page_a_place_page_a_part_of_the_country_and_routes_have_it(self):
|
||||
self.assertTrue(form_of(self.list_body("loops")))
|
||||
by_slug, _ = regions.collect_regions(self.records)
|
||||
self.assertGreaterEqual(len(by_slug["ca-on"]["records"]), home.FILTER_MIN)
|
||||
self.assertTrue(form_of(regions.region_page("ca-on", self.records, SITE)[2]))
|
||||
self.assertTrue(form_of(regions.group_page("central-canada", self.records, SITE)[2]))
|
||||
self.assertTrue(form_of(regions.routes_page(self.records, SITE)[2]))
|
||||
|
||||
def test_a_set_under_the_threshold_has_the_plain_rows(self):
|
||||
small = [k for k, recs in self.shown.items() if len(recs) < home.FILTER_MIN and k != "routes"]
|
||||
self.assertTrue(small)
|
||||
def test_every_state_province_and_list_page_has_the_bar_however_few_trails(self):
|
||||
by_slug, _ = regions.collect_regions(self.records)
|
||||
small = [k for k, v in by_slug.items() if len(v["records"]) < 10]
|
||||
self.assertGreater(len(small), 40)
|
||||
for key in small:
|
||||
body = self.list_body(key)
|
||||
self.assertFalse(form_of(body), key)
|
||||
self.assertNotIn("data-finder", str(body), key)
|
||||
body = regions.region_page(key, self.records, SITE)[2]
|
||||
self.assertIn('id="finder-form"', str(body), key)
|
||||
self.assertIn("data-finder", str(body), key)
|
||||
small_lists = [k for k, recs in self.shown.items() if len(recs) < 10 and k != "routes"]
|
||||
self.assertTrue(small_lists)
|
||||
for key in small_lists:
|
||||
self.assertTrue(form_of(self.list_body(key)), key)
|
||||
|
||||
def test_a_two_trail_page_offers_only_filters_that_narrow_it(self):
|
||||
by_slug, _ = regions.collect_regions(self.records)
|
||||
two = [k for k, v in by_slug.items() if len(v["records"]) == 2]
|
||||
self.assertTrue(two)
|
||||
for key in two:
|
||||
form = form_of(regions.region_page(key, self.records, SITE)[2])
|
||||
self.assertIn('name="q"', form, key)
|
||||
for sel in re.findall(r"<select[^>]*>(.*?)</select>", form, re.S):
|
||||
self.assertNotIn("<select></select>", sel)
|
||||
self.assertGreater(len(re.findall(r"<option", sel)), 1, key)
|
||||
|
||||
def test_the_tables_rankings_newest_authors_and_left_out_pages_do_not(self):
|
||||
bodies = {}
|
||||
@@ -102,14 +116,22 @@ class WhichPagesHaveTheBarTest(unittest.TestCase):
|
||||
from olt import authors
|
||||
groups = authors.author_pages(self.records, ROOT)
|
||||
bodies["authors"] = authors.index_page(self.records, SITE, ROOT)[2]
|
||||
big = max(groups, key=lambda g: len(g["routes"]))
|
||||
bodies["author"] = authors.author_page(big, self.records, SITE, groups)[2]
|
||||
bodies["left-out"] = leftout.left_out_page(leftout.load_entries(ROOT), SITE, ROOT)[2]
|
||||
self.assertGreater(len(bodies), 4)
|
||||
for name, body in bodies.items():
|
||||
self.assertNotIn('id="finder-form"', str(body), name)
|
||||
self.assertNotIn("data-finder", str(body), name)
|
||||
|
||||
def test_an_authors_own_page_has_the_bar_however_few_routes(self):
|
||||
from olt import authors
|
||||
groups = authors.author_pages(self.records, ROOT)
|
||||
for g in (min(groups, key=lambda g: len(g["routes"])), max(groups, key=lambda g: len(g["routes"]))):
|
||||
body = authors.author_page(g, self.records, SITE, groups)[2]
|
||||
self.assertIn('id="finder-form"', str(body), g["name"])
|
||||
|
||||
def test_a_set_with_no_trails_still_builds(self):
|
||||
self.assertIn("<form", str(home.finder_form([])))
|
||||
|
||||
def test_the_saved_page_has_no_bar(self):
|
||||
from olt import saved
|
||||
self.assertNotIn('id="finder-form"', str(saved.saved_page(self.records, SITE)[2]))
|
||||
|
||||
@@ -29,6 +29,31 @@ def infos(records):
|
||||
return places.collect(records, registry())
|
||||
|
||||
|
||||
class HomeWayInTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.records = wind_records(4) + yosemite_records(3)
|
||||
|
||||
def test_below_the_rows_a_line_links_each_kind_that_has_pages(self):
|
||||
body = str(home.render(self.records, S, ROOT, place_kinds=["park", "range", "wilderness"]))
|
||||
line = re.search(r'<p class="finder__foot finder__places">(.*?)</p>', body, re.S).group(1)
|
||||
self.assertEqual(
|
||||
re.sub(r"<[^>]+>", "", line),
|
||||
"Browse by park, by mountain range or by wilderness area.")
|
||||
for frag in ('href="/regions/#parks">park', 'href="/regions/#ranges">mountain range',
|
||||
'href="/regions/#wilderness">wilderness area'):
|
||||
self.assertIn(frag, line)
|
||||
# after the rows and the map, in the notes at the foot, never in the intro
|
||||
self.assertGreater(body.index("finder__places"), body.rindex('<li class="entry"'))
|
||||
self.assertGreater(body.index("finder__places"), body.index('id="browse-list"'))
|
||||
self.assertLess(body.index("</section>"), body.index("finder__places"))
|
||||
|
||||
def test_only_the_kinds_with_pages_and_none_when_there_are_none(self):
|
||||
line = re.search(r'finder__places">(.*?)</p>', str(home.render(self.records, S, ROOT, place_kinds=["range"])), re.S).group(1)
|
||||
self.assertEqual(re.sub(r"<[^>]+>", "", line), "Browse by mountain range.")
|
||||
self.assertNotIn("finder__places", str(home.render(self.records, S, ROOT)))
|
||||
|
||||
|
||||
class HubTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
@@ -48,18 +73,24 @@ class HubTest(unittest.TestCase):
|
||||
self.assertIn("Parks, mountain ranges and wilderness areas with three or more "
|
||||
"trails have pages too.", re.sub(r"\s+", " ", body))
|
||||
|
||||
def test_the_shortcut_strip_links_each_kind_that_has_pages(self):
|
||||
def test_a_jump_row_tops_the_hub_with_exact_counts_of_pages(self):
|
||||
_, _, body = regions.regions_index_page(self.records, S, infos=self.infos)
|
||||
strip = str(body)[str(body).index('<nav class="lists-row"'):]
|
||||
strip = strip[:strip.index("</nav>")]
|
||||
self.assertIn('<a href="#parks">Parks<span class="lists-row__n">1</span></a>', strip)
|
||||
self.assertIn('<a href="#ranges">Mountain ranges<span class="lists-row__n">1</span></a>', strip)
|
||||
self.assertNotIn("#wilderness", strip) # no wilderness page here: no shortcut
|
||||
# the regional groups are still there, before the kinds
|
||||
self.assertLess(strip.index('href="#west-coast"') if 'href="#west-coast"' in strip
|
||||
else strip.index("<li>"), strip.index('href="#parks"'))
|
||||
body = str(body)
|
||||
by_slug, _ = regions.collect_regions(self.records)
|
||||
row = body[body.index('<nav class="places-jump"'):]
|
||||
row = row[:row.index("</nav>")]
|
||||
self.assertLess(body.index('<nav class="places-jump"'), body.index("<h1>"))
|
||||
self.assertIn(f'<a href="#states-and-provinces">States and provinces <span class="places-jump__n">{len(by_slug)}</span></a>', row)
|
||||
self.assertIn('<a href="#parks">Parks <span class="places-jump__n">1</span></a>', row)
|
||||
self.assertIn('<a href="#ranges">Mountain ranges <span class="places-jump__n">1</span></a>', row)
|
||||
self.assertNotIn("#wilderness", row) # no wilderness page here: no link
|
||||
self.assertLess(row.index("#states-and-provinces"), row.index("#parks"))
|
||||
self.assertIn('id="states-and-provinces"', body)
|
||||
# the kinds are in the one row, not also in the strip of regional groups
|
||||
strip = body[body.index('<nav class="lists-row"'):]
|
||||
self.assertNotIn("#parks", strip[:strip.index("</nav>")])
|
||||
_, _, plain = regions.regions_index_page(self.records, S)
|
||||
self.assertNotIn('href="#parks"', str(plain))
|
||||
self.assertNotIn('class="places-jump"', str(plain))
|
||||
|
||||
def test_the_hub_still_lists_every_state_group_as_before(self):
|
||||
_, _, plain = regions.regions_index_page(self.records, S)
|
||||
@@ -67,7 +98,7 @@ class HubTest(unittest.TestCase):
|
||||
stripped = re.sub(r'<section class="places__group" aria-labelledby="(?:parks|ranges|wilderness)">.*?</section>',
|
||||
"", str(with_places), flags=re.S)
|
||||
stripped = stripped.replace(" or a kind of place", "")
|
||||
stripped = re.sub(r'<li><a href="#(?:parks|ranges|wilderness)">.*?</li>', "", stripped)
|
||||
stripped = re.sub(r'<nav class="places-jump".*?</nav>\s*', "", stripped, flags=re.S)
|
||||
stripped = stripped.replace(
|
||||
" Parks, mountain ranges and wilderness areas with three or more trails have pages too.", "")
|
||||
self.assertEqual(stripped, str(plain))
|
||||
|
||||
Reference in new issue
Block a user