From 807f26262f515aa87abb27b20a77cc843099f332 Mon Sep 17 00:00:00 2001 From: Emi Griffith Date: Wed, 15 Jul 2026 21:44:18 -0700 Subject: [PATCH] Climate hub: client-side search + alphabetical results (#110) Add a search box to /climate that filters to a flat, alphabetical list of matching cities (by city or country name), shown with their country; clearing it restores the collapsible directory. The index is built from the already-crawlable links, so it's a pure progressive enhancement (no SEO impact). Also sort cities alphabetically within each country in the directory (were population-ordered). --- cities.py | 6 ++-- templates/hub.html.j2 | 82 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 77 insertions(+), 11 deletions(-) diff --git a/cities.py b/cities.py index 67f7db8..2f48bb2 100644 --- a/cities.py +++ b/cities.py @@ -57,12 +57,12 @@ def display_name(city: dict) -> str: def by_country() -> dict[str, list[dict]]: - """Cities grouped by country (population-descending within each), country keys - ordered alphabetically — for the /climate hub's crawlable link graph.""" + """Cities grouped by country, both the countries and the cities within each + ordered alphabetically — for the /climate hub's crawlable link graph + search.""" groups: dict[str, list[dict]] = {} for c in _load(): key = c.get("country") or c.get("country_code") or "Other" groups.setdefault(key, []).append(c) for v in groups.values(): - v.sort(key=lambda x: -x["population"]) + v.sort(key=lambda x: x["name"].lower()) return dict(sorted(groups.items(), key=lambda kv: kv[0].lower())) diff --git a/templates/hub.html.j2 b/templates/hub.html.j2 index ef932bd..21fe005 100644 --- a/templates/hub.html.j2 +++ b/templates/hub.html.j2 @@ -11,13 +11,79 @@

Average temperatures by month, all-time records, and how today compares — for {{ n_cities }} cities across {{ n_countries }} countries. Every day is graded against that location's own ~45 years of climate history.

- {% for country, cs in groups.items() %} -
- {{ country }} {{ cs | length }} - -
- {% endfor %} + + + + +
+ {% for country, cs in groups.items() %} +
+ {{ country }} {{ cs | length }} + +
+ {% endfor %} +
+ +{% raw %} + +{% endraw %} {% endblock %}