Reword the lists in the words people search with: the longest names its longest trail first, short thru-hikes and loops under 100 and 200 miles, week-long and other backpacking trips, backpacking loops; the week list gains pages for states and places
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b75d39c7b6
commit
4c72fd705e
7 files changed
+118
-28
No files matched your search
+34
-22
@@ -55,6 +55,9 @@ class List:
|
||||
# (list's trails, all trails) -> a plain sentence or two that says what the list covers
|
||||
# where that is not every trail: how many have the fact the list is built on.
|
||||
note: Optional[Callable] = None
|
||||
# list's trails -> a first sentence for the list's page that answers the question the list is
|
||||
# asked as (the longest trail and its length), put before the blurb.
|
||||
lede: Optional[Callable] = None
|
||||
# A larger least size than MIN_SIZE, where the list is thin by nature (a month's list).
|
||||
min_size: int = 0
|
||||
# False for a list that is one of a fixed set, so none may go missing: a month's list, however
|
||||
@@ -69,6 +72,14 @@ def _km(mi):
|
||||
return words.fmt_int(mi * words.KM_PER_MI)
|
||||
|
||||
|
||||
def longest_lede(recs):
|
||||
"""The longest hiking trail of the list, by name and length, in the words the question is asked in."""
|
||||
top = max(recs, key=lambda r: (r["length_km"], r["id"]))
|
||||
where = "in the US" if "US" in common.countries(top) else "here"
|
||||
mi = words.fmt_int(top["derived"]["length_mi"])
|
||||
return f"The longest hiking trail {where} is {common.plain_name(top)}, {mi} miles ({words.fmt_int(top['length_km'])} km)."
|
||||
|
||||
|
||||
def _band(key):
|
||||
return lambda r: facets.time_band(r) == key
|
||||
|
||||
@@ -181,10 +192,11 @@ LISTS = (
|
||||
List("high-routes", "High routes",
|
||||
"Routes whose own name says High Route: through high country, often off the trail.",
|
||||
_high_route, page_title="High Routes: {n} Long Hiking Routes", group="walking"),
|
||||
List("longest", "The longest",
|
||||
List("longest", "The longest hiking trails",
|
||||
f"Trails of {LONG_MI:,} miles ({_km(LONG_MI)} km) or more.",
|
||||
lambda r: r["length_km"] >= LONG_KM, sort="length-desc",
|
||||
page_title=f"Longest Hiking Trails: {{n}} Trails of {LONG_MI:,}+ Miles", group="length"),
|
||||
page_title=f"Longest Hiking Trails in the US: {{n}} Trails of {LONG_MI:,}+ Miles", group="length",
|
||||
lede=longest_lede),
|
||||
List("500-to-1000-miles", f"{HALF_MI} to {LONG_MI:,} miles",
|
||||
f"Trails of {HALF_MI} miles ({_km(HALF_MI)} km) or more and shorter than {LONG_MI:,} miles ({_km(LONG_MI)} km).",
|
||||
_length_band(HALF_MI, LONG_MI), sort="length-desc",
|
||||
@@ -204,43 +216,43 @@ LISTS = (
|
||||
noun=f"Hiking Trails of {SHORT_MI} to {MID_MI} Miles",
|
||||
short=f"{SHORT_MI} to {MID_MI} Mile Trails"),
|
||||
List("under-100-miles", f"Under {SHORT_MI} miles",
|
||||
f"Trails shorter than {SHORT_MI} miles ({_km(SHORT_MI)} km).",
|
||||
f"Short thru-hikes and loops: trails shorter than {SHORT_MI} miles ({_km(SHORT_MI)} km).",
|
||||
lambda r: r["length_km"] < SHORT_KM, sort="length-asc",
|
||||
page_title=f"Hiking Trails Under {SHORT_MI} Miles: {{n}} Long Trails", group="length",
|
||||
noun=f"Hiking Trails Under {SHORT_MI} Miles",
|
||||
page_title=f"Short Thru-Hikes and Loops Under {SHORT_MI} Miles: {{n}} Trails", group="length",
|
||||
noun=f"Long Hikes Under {SHORT_MI} Miles",
|
||||
short=f"Trails Under {SHORT_MI} Miles"),
|
||||
List("under-200-miles", f"Under {MID_MI} miles",
|
||||
f"Trails shorter than {MID_MI} miles ({_km(MID_MI)} km): the two shortest bands together.",
|
||||
f"Short thru-hikes and loops: trails shorter than {MID_MI} miles ({_km(MID_MI)} km), the two shortest bands together.",
|
||||
lambda r: r["length_km"] < MID_KM, sort="length-asc",
|
||||
page_title=f"Thru-Hikes Under {MID_MI} Miles: {{n}} Long Trails", group="length"),
|
||||
page_title=f"Thru-Hikes and Loops Under {MID_MI} Miles: {{n}} Trails", group="length"),
|
||||
List("weekend", "A weekend or long weekend",
|
||||
f"Trails that take {WEEKEND_DAYS} days or fewer to walk whole.",
|
||||
f"Backpacking trips of {WEEKEND_DAYS} days or fewer: trails that take that long to walk whole.",
|
||||
lambda r: _mid_days(r) <= WEEKEND_DAYS, sort="time-asc",
|
||||
page_title="Long Trails to Hike in a Weekend: {n} Trails", group="time", note=time_note),
|
||||
page_title="Weekend Backpacking Trips: {n} Long Trails", group="time", note=time_note),
|
||||
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", page_title="Long Trails to Hike in a Week or Less: {n} Trails",
|
||||
group="time", note=time_note),
|
||||
"Week-long backpacking trips: 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", page_title="Week-Long Backpacking Trips: {n} Long Trails",
|
||||
group="time", note=time_note, noun="Week-Long Backpacking Trips", short="Week-Long Trips"),
|
||||
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", page_title="Long Trails to Hike in One to Two Weeks: {n} Trails",
|
||||
"Backpacking trips of one to two weeks, as a source states it or as estimated from the length.",
|
||||
_band("two-weeks"), sort="time-asc", page_title="One-to-Two-Week Backpacking Trips: {n} Long Trails",
|
||||
group="time", note=time_note),
|
||||
List("two-to-four-weeks", "Two weeks to a month",
|
||||
"Trails that take two to four weeks to walk whole.",
|
||||
_band("month"), sort="time-asc", page_title="Long Trails to Hike in 2 to 4 Weeks: {n} Trails",
|
||||
"Backpacking trips of two to four weeks: trails that take that long to walk whole.",
|
||||
_band("month"), sort="time-asc", page_title="Backpacking Trips of 2 to 4 Weeks: {n} Long Trails",
|
||||
group="time", note=time_note),
|
||||
List("a-month-or-more", "A month or more",
|
||||
"Trails that take more than four weeks to walk whole.",
|
||||
"Month-long backpacking trips and longer: trails that take more than four weeks to walk whole.",
|
||||
lambda r: facets.time_band(r) in ("months", "long"), sort="time-asc",
|
||||
page_title="Long Trails That Take a Month or More: {n} Trails", group="time", note=time_note),
|
||||
List("loops", "Loops", "Trails that finish where they start.",
|
||||
lambda r: facets.shape(r) == "loop", page_title="Loop Hiking Trails: {n} Long Trail Loops",
|
||||
group="walking", noun="Loop Hiking Trails",
|
||||
page_title="Month-Long Backpacking Trips and Longer: {n} Trails", group="time", note=time_note),
|
||||
List("loops", "Loops", "Backpacking loops: trails that finish where they start.",
|
||||
lambda r: facets.shape(r) == "loop", page_title="Backpacking Loops: {n} Long Trail Loops",
|
||||
group="walking", noun="Backpacking Loops",
|
||||
short="Loops"),
|
||||
List("off-trail", "Cross-country",
|
||||
"Trails with stretches of walking where there is no trail.",
|
||||
lambda r: facets.walking(r) in facets.CROSS_COUNTRY,
|
||||
page_title="Cross-Country Hiking: {n} Long Trails and Routes", group="walking",
|
||||
page_title="Cross-Country Hiking: {n} Long Trails", group="walking",
|
||||
noun="Cross-Country Hiking",
|
||||
short="Cross-Country Hikes"),
|
||||
List("mostly-cross-country", "Mostly cross-country",
|
||||
|
||||
+3
-2
@@ -528,7 +528,7 @@ def list_page(lst, recs, total, site, *, records=None, before="", after="", lead
|
||||
<header class="titleblock"><div class="titleblock__text">
|
||||
<p class="kicker">A list</p>
|
||||
<h1>{esc(lst.title)}</h1>
|
||||
<p class="page-head__lede">{esc(lst.blurb)} {_plural(len(recs))}, {n_gpx} with a GPX here.</p>
|
||||
<p class="page-head__lede">{esc(lst.lede(recs) + " " if lst.lede else "")}{esc(lst.blurb)} {_plural(len(recs))}, {n_gpx} with a GPX here.</p>
|
||||
</div></header>
|
||||
</div></div>
|
||||
<div class="container section place">
|
||||
@@ -543,7 +543,8 @@ def list_page(lst, recs, total, site, *, records=None, before="", after="", lead
|
||||
stats = [f" {_plural(len(recs))}, from {common.plain_name(by_length[0])}, {_miles(by_length[0])} miles, "
|
||||
f"to {common.plain_name(by_length[-1])}, {_miles(by_length[-1])} miles; {_with_gpx(n_gpx, len(recs)) or 'none with a GPX here'}.",
|
||||
f" {_plural(len(recs))}, {_with_gpx(n_gpx, len(recs)) or 'none with a GPX here'}.", f" {_plural(len(recs))}."]
|
||||
desc = _fit([lst.blurb + s for s in stats] + [lst.blurb])
|
||||
first = f"{lst.lede(recs)} " if lst.lede else ""
|
||||
desc = _fit([first + lst.blurb + s for s in stats] + [first + lst.blurb, lst.blurb])
|
||||
return lst.search_title(len(recs)), desc, Markup(body), home.has_overview_map(recs)
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"/regions/mountain-west/": "6151f5a28d366fb48aab7027f08cea6da425201d0e7327780a01dd77cedc7bc7",
|
||||
"/regions/north/": "85ba3ea850c2df690e311cf09257f2548ed888c07c319a01fd30d5e19cdf1fd4",
|
||||
"/regions/us-co/": "97daaf3511578896b222570cba630da2d8ca0571504ce43b3685dbe532e40f56",
|
||||
"/regions/us-co/loops/": "03896834b5369655f7b5f26634b6d23c834b17f1a25b0ec328d44934e20e2dfa",
|
||||
"/regions/us-co/loops/": "5a116735c701f1840ad00646a02682afc177c585fc06763f5b5a6b8afccff4a8",
|
||||
"/regions/us-co/with-gpx/": "d82eace3d70eb9b1ef1346f5a3470199bd6a00e6e104fe661bfeb80199af96b8",
|
||||
"/regions/us-hi/": "1e5681ffbd50e382db7d69528fde602069006bf0cddad494d817369224bd96ad",
|
||||
"/regions/us-ut/": "906db4153def35fa5418d0b86dba908fd27396bbc2098978ee169516e1b39785",
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
"""The wording of the ready-made lists (olt/browse.py): titles in the words people search with.
|
||||
Addresses and rules do not change; only title, blurb, page_title, noun and lede."""
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
WEB = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, WEB)
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
from olt import browse, common, records # noqa: E402
|
||||
from test_facets import BANNED # noqa: E402
|
||||
|
||||
KEYS = ['national-scenic-trails', 'national-recreation-trails', 'routes', 'high-routes', 'longest', '500-to-1000-miles', '200-to-500-miles', '100-to-200-miles', 'under-100-miles', 'under-200-miles', 'weekend', 'a-week-or-less', 'one-to-two-weeks', 'two-to-four-weeks', 'a-month-or-more', 'loops', 'off-trail', 'mostly-cross-country', 'unfinished', 'parks-canada', 'forest-service', 'state-and-provincial-parks', 'clubs-and-associations', 'with-gpx', 'canada', 'united-states', 'terrain-alpine', 'terrain-forest', 'terrain-desert', 'terrain-coast', 'terrain-prairie', 'terrain-canyon', 'terrain-tundra', 'terrain-lakes', 'terrain-farmland', 'hike-in-january', 'hike-in-february', 'hike-in-march', 'hike-in-april', 'hike-in-may', 'hike-in-june', 'hike-in-july', 'hike-in-august', 'hike-in-september', 'hike-in-october', 'hike-in-november', 'hike-in-december']
|
||||
|
||||
|
||||
class ListWordingTest(unittest.TestCase):
|
||||
def test_list_urls_and_keys_are_unchanged(self):
|
||||
self.assertEqual([lst.key for lst in browse.LISTS], KEYS)
|
||||
self.assertEqual(browse.path(browse.by_key("loops")), "/lists/loops/")
|
||||
self.assertEqual(browse.path(browse.by_key("routes")), "/routes/")
|
||||
|
||||
def test_the_reworded_lists_have_the_new_page_titles(self):
|
||||
want = {
|
||||
"longest": "Longest Hiking Trails in the US: 7 Trails of 1,000+ Miles",
|
||||
"under-100-miles": "Short Thru-Hikes and Loops Under 100 Miles: 7 Trails",
|
||||
"under-200-miles": "Thru-Hikes and Loops Under 200 Miles: 7 Trails",
|
||||
"a-week-or-less": "Week-Long Backpacking Trips: 7 Long Trails",
|
||||
"loops": "Backpacking Loops: 7 Long Trail Loops",
|
||||
}
|
||||
for key, title in want.items():
|
||||
self.assertEqual(browse.by_key(key).search_title(7), title)
|
||||
|
||||
def test_a_loop_is_never_called_a_thru_hike_alone(self):
|
||||
# the length bands hold loops too, so their titles say so
|
||||
for key in ("under-100-miles", "under-200-miles"):
|
||||
self.assertIn("Loops", browse.by_key(key).page_title)
|
||||
self.assertNotIn("thru", browse.by_key("loops").page_title.lower())
|
||||
|
||||
def test_the_week_band_has_a_noun_and_loops_say_backpacking(self):
|
||||
self.assertEqual(browse.by_key("a-week-or-less").noun, "Week-Long Backpacking Trips")
|
||||
self.assertEqual(browse.by_key("loops").noun, "Backpacking Loops")
|
||||
|
||||
def test_no_banned_word_and_no_best_in_any_list_wording(self):
|
||||
for lst in browse.LISTS:
|
||||
for text in (lst.title, lst.blurb, lst.search_title(9), lst.noun, lst.short):
|
||||
for pattern in BANNED:
|
||||
self.assertIsNone(re.search(pattern, text, re.I), (lst.key, text))
|
||||
self.assertIsNone(re.search(r"\bbest\b", text, re.I), (lst.key, text))
|
||||
|
||||
def test_every_search_title_is_unique_and_fits(self):
|
||||
titles = [lst.search_title(99) for lst in browse.LISTS]
|
||||
self.assertEqual(len(titles), len(set(titles)))
|
||||
for t in titles:
|
||||
self.assertLessEqual(len(t), common.TITLE_LIMIT, t)
|
||||
|
||||
def test_the_longest_list_names_the_longest_trail_and_its_length_first(self):
|
||||
recs = records.load_records(records.ROOT)
|
||||
lst = browse.by_key("longest")
|
||||
top = max(browse.members(lst, recs), key=lambda r: (r["length_km"], r["id"]))
|
||||
first = lst.lede(browse.members(lst, recs))
|
||||
self.assertTrue(first.startswith("The longest hiking trail"), first)
|
||||
self.assertIn(common.plain_name(top), first)
|
||||
self.assertIn(f"{top['derived']['length_mi']:,.0f} miles", first)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -188,13 +188,13 @@ class PlaceAndListTitleTest(unittest.TestCase):
|
||||
title = lst.search_title(999)
|
||||
self.assertLessEqual(len(title), ROOM, title)
|
||||
self.assertIn("999", title)
|
||||
self.assertEqual(browse.by_key("loops").search_title(32), "Loop Hiking Trails: 32 Long Trail Loops")
|
||||
self.assertEqual(browse.by_key("loops").search_title(32), "Backpacking Loops: 32 Long Trail Loops")
|
||||
|
||||
def test_list_description_adds_to_the_title(self):
|
||||
lst = browse.by_key("under-100-miles")
|
||||
members = browse.members(lst, [fake(i, km=100) for i in range(1, 5)])
|
||||
title, desc = regions.list_page(lst, members, 20, S)[:2]
|
||||
self.assertTrue(title.startswith("Hiking Trails Under 100 Miles: 4"))
|
||||
self.assertTrue(title.startswith("Short Thru-Hikes and Loops Under 100 Miles: 4"))
|
||||
self.assertLessEqual(len(desc), common.DESCRIPTION_LIMIT)
|
||||
self.assertTrue(desc.startswith(lst.blurb))
|
||||
self.assertIn("4 trails", desc)
|
||||
|
||||
@@ -55,7 +55,7 @@ class LengthBandTest(unittest.TestCase):
|
||||
def test_under_200_is_the_two_short_bands(self):
|
||||
recs = [fake(1, km=mi(50)), fake(2, km=mi(150)), fake(3, km=mi(250))]
|
||||
self.assertEqual(sorted(keys(recs, "under-200-miles")), ["t1", "t2"])
|
||||
self.assertTrue(browse.by_key("under-200-miles").search_title(9).startswith("Thru-Hikes Under 200 Miles"))
|
||||
self.assertTrue(browse.by_key("under-200-miles").search_title(9).startswith("Thru-Hikes and Loops Under 200 Miles"))
|
||||
|
||||
|
||||
class TimeListTest(unittest.TestCase):
|
||||
|
||||
Reference in new issue
Block a user