2fd28fa719
Housekeeping per Codex: - Mirror the live @newsHidden rule into deploy/caddy/Caddyfile.snapshot so the /news noindex protection is reproducibly recorded. - Extract the feed's routing helpers (feedBase/parseView/viewUrl) into pure $lib/feednav.js and unit-test them (the base-aware URL generation wasn't exercised by the prior suite). NewsFeed imports them; behavior unchanged. (Note: the step-1 commit also swept in data/wotd_audio/renewal.mp3 — a legit cached pronunciation, not extraction-related; left as-is per Codex.) 32 frontend tests green; build clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
29 lines
1.4 KiB
JavaScript
29 lines
1.4 KiB
JavaScript
// 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);
|
|
}
|