Fix feature detection for explore and add community

explore lives at /u/{handle}/athlete/explore/ — was classified as
profile. Add path-contains check so it's detected correctly.
Add community (/community/) which was falling into the feed catchall.
Extend feature map tuples to (host, startswith, contains, label).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Davide Scaini
2026-05-18 22:03:40 +02:00
parent 5d2e2443a3
commit 1f6239e7d2
+19 -14
View File
@@ -69,18 +69,21 @@ def _is_bot(ua: str, path: str) -> bool:
# ── Feature mapping (from Referer header) ─────────────────────────────────────
# Evaluated in order: first match wins. None label = exclude.
_FEATURE_MAP: list[tuple[str, str | None, str | None]] = [
("planner.bincio.org", None, "planner"),
("wiki.bincio.org", None, "wiki"),
("activity.bincio.org", "/admin/", None), # exclude admin polling
("activity.bincio.org", "/activity/", "activity"),
("activity.bincio.org", "/segments/", "segments"),
("activity.bincio.org", "/stats/", "stats"),
("activity.bincio.org", "/explore/", "explore"),
("activity.bincio.org", "/ideas/", "ideas"),
("activity.bincio.org", "/u/", "profile"),
("activity.bincio.org", None, "feed"),
("bincio.org", None, "hub"),
# Tuple: (host, path_startswith_or_None, path_contains_or_None, label_or_None)
_FEATURE_MAP: list[tuple[str, str | None, str | None, str | None]] = [
("planner.bincio.org", None, None, "planner"),
("wiki.bincio.org", None, None, "wiki"),
("activity.bincio.org", "/admin/", None, None), # exclude
("activity.bincio.org", "/activity/", None, "activity"),
("activity.bincio.org", "/segments/", None, "segments"),
("activity.bincio.org", "/stats/", None, "stats"),
("activity.bincio.org", "/community/", None, "community"),
("activity.bincio.org", "/ideas/", None, "ideas"),
# explore lives at /u/{handle}/athlete/explore/ — check before generic /u/
("activity.bincio.org", "/u/", "athlete/explore", "explore"),
("activity.bincio.org", "/u/", None, "profile"),
("activity.bincio.org", None, None, "feed"),
("bincio.org", None, None, "hub"),
]
FEATURE_COLORS = {
@@ -91,6 +94,7 @@ FEATURE_COLORS = {
"wiki": "#a855f7",
"ideas": "#f43f5e",
"explore": "#34d399",
"community": "#22d3ee",
"profile": "#94a3b8",
"hub": "#64748b",
"stats": "#e879a0",
@@ -105,9 +109,10 @@ def _feature(referer: str) -> str | None:
path = p.path
except Exception:
return None
for h, prefix, label in _FEATURE_MAP:
for h, prefix, contains, label in _FEATURE_MAP:
if host == h:
if prefix is None or path.startswith(prefix):
if (prefix is None or path.startswith(prefix)) and \
(contains is None or contains in path):
return label
return None