diff --git a/frontend/src/routes/+page.svelte b/frontend/src/routes/+page.svelte index 6cf0835..ecfedb3 100644 --- a/frontend/src/routes/+page.svelte +++ b/frontend/src/routes/+page.svelte @@ -738,7 +738,10 @@ {/each} - + + + + {/if}
@@ -1047,7 +1050,7 @@ background: var(--bg); color: var(--ink); cursor: pointer; border-right: 1px solid var(--line); } .sd-stops .sd-btn:last-child { border-right: none; } .sd-btn.on { background: var(--accent-soft); color: var(--accent-deep); } - .sd-change { margin-left: auto; } + .sd-actions { margin-left: auto; display: inline-flex; gap: 12px; } .feed-section { grid-column: 1 / -1; margin: 8px 0 2px; font-family: var(--label); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); } .grid > .feed-section:first-child { margin-top: 0; } diff --git a/goodnews/api.py b/goodnews/api.py index 2a52673..a26c582 100644 --- a/goodnews/api.py +++ b/goodnews/api.py @@ -2236,7 +2236,16 @@ def create_app() -> FastAPI: have.add(a["id"]) # Lead with a gentle, readable story (charged or paywalled stories stay # in the set, just not as the first thing seen). - items = _pick_lead(items) + if home_country and scope != "world" and items: + # Keep "closest first": pick the gentlest hero from ONLY the closest non-empty + # section, so _pick_lead can never float a wider-region/world story above a + # local one. Wider tiers stay in their order behind it. + lead = items[0].get("__section") + head = [a for a in items if a.get("__section") == lead] + tail = [a for a in items if a.get("__section") != lead] + items = _pick_lead(head) + tail + else: + items = _pick_lead(items) return BriefResponse( brief_date=data["brief_date"], title=data["title"], diff --git a/tests/test_geo_feed.py b/tests/test_geo_feed.py index 42fa0e2..a9279ee 100644 --- a/tests/test_geo_feed.py +++ b/tests/test_geo_feed.py @@ -87,6 +87,7 @@ def test_home_brief_leads_with_local(app_db): # NY story (#5). CA stories (a different census region) fall to 'country'. r = TestClient(app_db).get("/api/brief?home=US-NY&limit=10").json() assert r["title"] == "Close to home" + assert r["items"][0]["section"] == "state" # hero comes from the closest section state_ids = {it["id"] for it in r["items"] if it["section"] == "state"} assert state_ids == {1, 2, 3, 4} # high-conf NY only a5 = next(it for it in r["items"] if it["id"] == 5)