Offer every trip-length band in the home page's shortcut row, and fade its edge on a phone
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
5b0219eaea
commit
985eaa2074
3 files changed
+54
-3
No files matched your search
@@ -2276,7 +2276,10 @@ td .linklist a { font-weight: 400; }
|
||||
@media (max-width: 39.99rem) {
|
||||
.lists-row ul {
|
||||
flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; clip-path: none;
|
||||
margin-inline: calc(-1 * var(--gutter)); padding-inline: calc(var(--gutter) - 0.8em) var(--gutter);
|
||||
margin-inline: calc(-1 * var(--gutter)); padding-inline: calc(var(--gutter) - 0.8em) 2rem;
|
||||
/* The last 2rem fades out, the one cue that the line goes on; at the end of the scroll the padding sits under it. */
|
||||
-webkit-mask-image: linear-gradient(to right, #000 calc(100% - 2rem), transparent);
|
||||
mask-image: linear-gradient(to right, #000 calc(100% - 2rem), transparent);
|
||||
}
|
||||
.lists-row li:first-child::before { visibility: hidden; }
|
||||
.lists-row ul::-webkit-scrollbar { display: none; }
|
||||
|
||||
+28
-1
@@ -782,15 +782,42 @@ def has_overview_map(recs, scope=""):
|
||||
return n > 0 and (scope == "all" or n >= MAP_MIN)
|
||||
|
||||
|
||||
def time_band_keys(keys, have, records):
|
||||
"""keys (list keys, in the row's order) with a list added for each of the filter's trip-length bands
|
||||
(facets.TIME_BANDS) that none of them covers, so the row offers every band the Time filter does. A list
|
||||
covers a band when every trail in the band is in it; the one with the fewest trails is the one that
|
||||
stands for the band. The added list goes after the last list that covers an earlier band. A row that
|
||||
holds no trip length at all is returned as it is."""
|
||||
time_lists = [(lst, recs) for lst, recs in have.values() if lst.group == "time" and lst.key != "weekend"]
|
||||
keys = list(keys)
|
||||
if not any(k in {lst.key for lst, _ in time_lists} for k in keys):
|
||||
return keys # a row with no trip length in it (a data file that left them out) is left as it is
|
||||
last = None
|
||||
for band, _, _ in facets.TIME_BANDS:
|
||||
members = [r for r in records if facets.time_band(r) == band]
|
||||
covering = [(len(recs), lst.key) for lst, recs in time_lists if members and all(lst.test(r) for r in members)]
|
||||
if not covering:
|
||||
continue
|
||||
if any(k in keys for _, k in covering):
|
||||
last = max(keys.index(k) for _, k in covering if k in keys)
|
||||
continue
|
||||
key = min(covering)[1]
|
||||
at = last + 1 if last is not None else len(keys)
|
||||
keys.insert(at, key)
|
||||
last = at
|
||||
return keys
|
||||
|
||||
|
||||
def lists_row(records, picks=()):
|
||||
"""The row of lists under the home page's headline: the lists the data file marks for it (picks,
|
||||
from datafiles.home_lists: key and position), in that order, each with its count, then "All
|
||||
lists". A marked list that is not shown today (too few trails, or nearly all of them) is left out."""
|
||||
have = {lst.key: (lst, recs) for lst, recs in browse.shown(records)}
|
||||
keys = time_band_keys([k for k in picks if k in have], have, records)
|
||||
items = "".join(
|
||||
f'<li><a href="{esc(browse.path(have[key][0]))}">{esc(have[key][0].title)}'
|
||||
f'<span class="lists-row__n">{len(have[key][1])}</span></a></li>'
|
||||
for key in picks if key in have)
|
||||
for key in keys)
|
||||
if not items:
|
||||
return ""
|
||||
return f"""<nav class="lists-row" aria-labelledby="lists-title">
|
||||
|
||||
@@ -19,7 +19,7 @@ ROOT = os.path.dirname(WEB)
|
||||
sys.path.insert(0, WEB)
|
||||
sys.path.insert(0, os.path.join(ROOT, "tools"))
|
||||
|
||||
from olt import browse, common, datafiles, home, layout, pagekit, records, site, sketch, trail # noqa: E402
|
||||
from olt import browse, common, datafiles, facets, home, layout, pagekit, records, site, sketch, trail # noqa: E402
|
||||
|
||||
SITE = site.load()
|
||||
|
||||
@@ -58,6 +58,8 @@ class HomePageTest(unittest.TestCase):
|
||||
"a-week-or-less", "one-to-two-weeks", "a-month-or-more", "with-gpx", "canada"])
|
||||
row = home.lists_row(self.recs, keys)
|
||||
titles = re.findall(r'<li><a href="[^"]+">(.*?)<span class="lists-row__n">', row)
|
||||
# the file's lists in its order, with the trip-length band it leaves out added where it belongs
|
||||
keys = keys[:7] + ["two-to-four-weeks"] + keys[7:]
|
||||
self.assertEqual(titles, [browse.by_key(k).title for k in keys])
|
||||
self.assertTrue(row.rstrip().endswith("</nav>"))
|
||||
self.assertIn('<li class="lists-row__all"><a href="/lists/">All lists</a></li></ul>', row)
|
||||
@@ -68,6 +70,25 @@ class HomePageTest(unittest.TestCase):
|
||||
self.assertEqual(other, ["routes", "loops"])
|
||||
self.assertEqual(re.findall(r'<li><a href="[^"]+">(.*?)<span', home.lists_row(self.recs, other)), ["Routes", "Loops"])
|
||||
|
||||
def test_the_row_offers_every_trip_length_band_the_time_filter_does(self):
|
||||
row = home.lists_row(self.recs, home.home_picks(datafiles.lists(ROOT)))
|
||||
linked = [browse.by_key(k) for k in re.findall(r'href="/lists/([^/"]+)/"', row)]
|
||||
for band, label, _ in facets.TIME_BANDS:
|
||||
members = [r for r in self.recs if facets.time_band(r) == band]
|
||||
self.assertTrue(members, band)
|
||||
self.assertTrue(any(all(lst.test(r) for r in members) for lst in linked if lst.group == "time"),
|
||||
f"no chip for {label}")
|
||||
self.assertIn("Two weeks to a month", row)
|
||||
self.assertNotIn("weekend", row.lower())
|
||||
# a row the data file gives with no trip length is not given one
|
||||
self.assertNotIn("weeks", home.lists_row(self.recs, ["loops", "routes"]))
|
||||
|
||||
def test_a_row_that_scrolls_sideways_fades_at_its_edge(self):
|
||||
css = read(WEB, "assets", "style.css")
|
||||
phone = css[css.index(".lists-row ul {\n flex-wrap: nowrap"):]
|
||||
phone = phone[:phone.index("}")]
|
||||
self.assertIn("mask-image: linear-gradient(to right", phone)
|
||||
|
||||
def test_the_introduction_is_the_headline_its_sentence_and_the_lists(self):
|
||||
intro = self.body[:self.body.index('class="container home"')]
|
||||
self.assertIn('<section class="intro"', intro)
|
||||
|
||||
Reference in new issue
Block a user