SEO: climate hub — collapse all countries by default, order alphabetically (#104)
Drop the open-by-default on the first three countries (every <details> starts collapsed) and order the country sections alphabetically instead of by largest city's population.
This commit is contained in:
parent
586a7b1aa1
commit
0e16ad2a93
2 changed files with 3 additions and 4 deletions
|
|
@ -58,12 +58,11 @@ def display_name(city: dict) -> str:
|
||||||
|
|
||||||
def by_country() -> dict[str, list[dict]]:
|
def by_country() -> dict[str, list[dict]]:
|
||||||
"""Cities grouped by country (population-descending within each), country keys
|
"""Cities grouped by country (population-descending within each), country keys
|
||||||
ordered by their largest city — for the /climate hub's crawlable link graph."""
|
ordered alphabetically — for the /climate hub's crawlable link graph."""
|
||||||
groups: dict[str, list[dict]] = {}
|
groups: dict[str, list[dict]] = {}
|
||||||
for c in _load():
|
for c in _load():
|
||||||
key = c.get("country") or c.get("country_code") or "Other"
|
key = c.get("country") or c.get("country_code") or "Other"
|
||||||
groups.setdefault(key, []).append(c)
|
groups.setdefault(key, []).append(c)
|
||||||
for v in groups.values():
|
for v in groups.values():
|
||||||
v.sort(key=lambda x: -x["population"])
|
v.sort(key=lambda x: -x["population"])
|
||||||
# order countries by their biggest city's population (most prominent first)
|
return dict(sorted(groups.items(), key=lambda kv: kv[0].lower()))
|
||||||
return dict(sorted(groups.items(), key=lambda kv: -kv[1][0]["population"]))
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
{{ n_cities }} cities across {{ n_countries }} countries. Every day is graded against that
|
{{ n_cities }} cities across {{ n_countries }} countries. Every day is graded against that
|
||||||
location's own ~45 years of climate history.</p>
|
location's own ~45 years of climate history.</p>
|
||||||
{% for country, cs in groups.items() %}
|
{% for country, cs in groups.items() %}
|
||||||
<details class="hub-country"{% if loop.index <= 3 %} open{% endif %}>
|
<details class="hub-country">
|
||||||
<summary>{{ country }} <span class="hub-count">{{ cs | length }}</span></summary>
|
<summary>{{ country }} <span class="hub-count">{{ cs | length }}</span></summary>
|
||||||
<ul class="city-links">
|
<ul class="city-links">
|
||||||
{% for c in cs %}<li><a href="{{ base }}/climate/{{ c.slug }}">{{ c.name }}</a></li>{% endfor %}
|
{% for c in cs %}<li><a href="{{ base }}/climate/{{ c.slug }}">{{ c.name }}</a></li>{% endfor %}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue