// Pure routing helpers for the news feed, shared by its two mounts: `/` (interim, // becomes the hub at cutover) and `/news` (its permanent home). Kept framework-free // so they're unit-testable without mounting the Svelte component. // Which base path the feed is rendering at. `/news` is permanent; `/` is the interim // mount. Anything not under /news is treated as `/`. export function feedBase(pathname) { return (pathname || '').startsWith('/news') ? '/news' : '/'; } // The current view key, derived from query params only (path-agnostic, so a deep link // works at either base): search > source > tag > explicit view > 'today' (Highlights). export function parseView(url) { const p = url.searchParams; if ((p.get('q') || '').trim()) return 'search'; if (p.get('source')) return 'source:' + p.get('source'); if (p.get('tag')) return 'tag:' + p.get('tag'); return p.get('view') || 'today'; } // A link to a view at the given base path. 'today' is the bare base; everything else // carries its query param so the same parseView() reads it back identically. export function viewUrl(base, key) { if (key === 'today') return base; if (key.startsWith('source:')) return base + '?source=' + encodeURIComponent(key.slice(7)); if (key.startsWith('tag:')) return base + '?tag=' + encodeURIComponent(key.slice(4)); return base + '?view=' + encodeURIComponent(key); }