Say "35 trails", not "35 of 35 trails", when nothing is filtered out
Mirror to forge / mirror (push) Canceled after 0s
Validate / validate (push) Canceled after 0s
Validate / history (push) Canceled after 0s
Validate / site (push) Canceled after 0s
Validate / deploy (push) Canceled after 0s

The count above each set of rows keeps the "12 of 35 trails" form only
when some are filtered out, in the built pages and in the script alike.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-18 10:06:31 -07:00
1 parent 76622257b7
commit 5abd7b1ede
5 files changed
+50 -5

No files matched your search

+10 -3
View File
@@ -1545,7 +1545,13 @@
return out;
}
return { passes: passes, count: count };
/* The words after the figure of the count above a list: "trails" when every one is shown,
"of 35 trails" when some are left out. */
function countWords(shown, total, noun) {
return (shown === total ? '' : 'of ' + total + ' ') + noun;
}
return { passes: passes, count: count, countWords: countWords };
})();
/* facet-counts:end */
@@ -1926,13 +1932,14 @@
ol.hidden = !any;
if (head && head.classList.contains('results__group')) head.hidden = !any;
});
var text = shown.length + ' of ' + total + ' ' + noun;
var words = FacetCount.countWords(shown.length, total, noun);
var text = shown.length + ' ' + words;
if (count && count.textContent !== text) {
count.innerHTML = '';
var strong = document.createElement('strong');
strong.textContent = String(shown.length);
count.appendChild(strong);
count.appendChild(document.createTextNode(' of ' + total + ' ' + noun));
count.appendChild(document.createTextNode(' ' + words));
}
if (empty) empty.hidden = shown.length > 0;
if (listHead) listHead.hidden = shown.length === 0;
+1 -1
View File
@@ -578,7 +578,7 @@ def results(recs=None, *, finder=False, groups=None, routes_list=False, default_
lists += f'\n <ol class="entries"{list_id}{every}>\n{rows}\n </ol>'
if finder:
count = (f'<p class="results-count" id="results-count" role="status" data-noun="{noun}">'
f'<strong>{total}</strong> of {total} {noun}</p>')
f'<strong>{total}</strong> {noun}</p>')
empty = f"""
<div class="empty-state" id="empty-state" hidden>
<p><strong>No {noun} match these filters.</strong></p>
+2 -1
View File
@@ -297,7 +297,8 @@ class BuiltVocabularyTest(unittest.TestCase):
doc = self.read("index.html")
n = len(re.findall(r'<li class="entry" ', doc))
self.assertEqual(n, len(records.load_records(ROOT)))
self.assertIn(f"<strong>{n}</strong> of {n} trails", doc)
self.assertIn(f"<strong>{n}</strong> trails</p>", doc)
self.assertNotIn(f"{n} of {n}", doc)
self.assertIn(f"{n} trails. Narrow them", doc)
def test_route_badges_link_to_the_routes_list(self):
+33
View File
@@ -319,6 +319,39 @@ class CountsAreTrueTest(unittest.TestCase):
self.assertIn("var c = FacetCount.count(rows, s, lengthSteps());", js)
class CountWordsTest(unittest.TestCase):
"""The count above a list: "35 trails" when none is left out, "12 of 35 trails" when some are."""
@staticmethod
def count_of(body):
m = re.search(r'<p class="results-count"[^>]*><strong>([^<]*)</strong>([^<]*)</p>', str(body))
return m.group(1) + m.group(2)
def test_a_page_with_nothing_filtered_reads_the_plain_count(self):
records = Pages.recs()
lst = browse.LISTS[0]
recs = browse.members(lst, records)
pages = {"home": home.render(records, SITE, ROOT),
"list": regions.list_page(lst, recs, len(records), SITE, records=records)[2]}
for name, body in pages.items():
if 'id="results-count"' not in str(body):
continue
text = self.count_of(body)
self.assertRegex(text, r"^[\d,]+ (trails?|routes?)$", name)
self.assertNotRegex(str(body), r"\b(\d[\d,]*) of \1\b", name)
@unittest.skipUnless(NODE, "node is not installed")
def test_the_script_words_the_count_both_ways(self):
prog = facet_count_source() + """
var c = [[35, 35, 'trails'], [12, 35, 'trails'], [1, 1, 'trail'], [1, 58, 'routes'], [0, 58, 'routes'], [58, 58, 'routes']]
.map(function (a) { return a[0] + ' ' + FacetCount.countWords(a[0], a[1], a[2]); });
process.stdout.write(JSON.stringify(c));
"""
out = subprocess.run([NODE, "-e", prog], capture_output=True, text=True, check=True)
self.assertEqual(json.loads(out.stdout), ["35 trails", "12 of 35 trails", "1 trail", "1 of 58 routes",
"0 of 58 routes", "58 routes"])
class PanelInTheFlowTest(unittest.TestCase):
def test_the_open_panel_is_not_laid_over_the_rows(self):
css = read(WEB, "assets", "style.css")