GET /xrpc/app.bsky.actor.searchActorsTypeahead typeahead.waow.tech
16
fork

Configure Feed

Select the types of activity you want to include in your feed.

attribute homepage searches + handle special domains in pie chart

same-origin fetches don't send Origin, so fall back to Referer to
detect searches from our own homepage. both "homepage" and "unknown"
get muted gray colors and aren't rendered as links in the legend.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+21 -4
+21 -4
src/index.ts
··· 337 337 async function recordTrafficSource(db: TursoDB, request: Request): Promise<void> { 338 338 const client = request.headers.get("X-Client"); 339 339 const origin = request.headers.get("Origin"); 340 - const domain = client || (origin ? new URL(origin).hostname : "unknown"); 340 + const referer = request.headers.get("Referer"); 341 + const selfHost = new URL(request.url).hostname; 342 + 343 + let domain: string; 344 + if (client) { 345 + domain = client; 346 + } else if (origin) { 347 + domain = new URL(origin).hostname; 348 + } else if (referer) { 349 + try { 350 + const refHost = new URL(referer).hostname; 351 + domain = refHost === selfHost ? "homepage" : refHost; 352 + } catch { domain = "unknown"; } 353 + } else { 354 + domain = "unknown"; 355 + } 341 356 await db.prepare( 342 357 `INSERT INTO traffic_sources (domain, hits) 343 358 VALUES (?1, 1) ··· 696 711 697 712 const PIE_COLORS = ['#4a9', '#58a6ff', '#bc8cff', '#e5a04b', '#e06c75', '#56b6c2', '#c678dd', '#98c379', '#d19a66']; 698 713 const trafficTotal = d.trafficSources.reduce((s, r) => s + r.hits, 0); 714 + const SPECIAL_DOMAINS: Record<string, string> = { unknown: '#555', homepage: '#666' }; 699 715 const pieLegendHtml = d.trafficSources.map((r, i) => { 700 - const color = r.domain === 'unknown' ? '#555' : PIE_COLORS[i % PIE_COLORS.length]; 716 + const color = SPECIAL_DOMAINS[r.domain] ?? PIE_COLORS[i % PIE_COLORS.length]; 701 717 const pct = trafficTotal > 0 ? ((r.hits / trafficTotal) * 100).toFixed(1) : '0'; 702 - const label = r.domain === 'unknown' 718 + const label = r.domain in SPECIAL_DOMAINS 703 719 ? r.domain 704 720 : `<a href="https://${r.domain}" target="_blank" rel="noopener" class="legend-link">${r.domain}</a>`; 705 721 return `<span><span class="ldot" style="background:${color}"></span>${label} (${pct}%)</span>`; ··· 1033 1049 if (pieCanvas && traffic.length > 0) { 1034 1050 const pieTotal = traffic.reduce((s, r) => s + r.hits, 0); 1035 1051 1052 + const SPECIAL = { unknown: '#555', homepage: '#666' }; 1036 1053 function getColor(i) { 1037 - return traffic[i].domain === 'unknown' ? '#555' : PIE_COLORS[i % PIE_COLORS.length]; 1054 + return SPECIAL[traffic[i].domain] || PIE_COLORS[i % PIE_COLORS.length]; 1038 1055 } 1039 1056 1040 1057 // build segments: { start, end, color, domain, hits }