Files
CatoandClaude 0b6ec077a3 fix(nav): /portal reaches the desk, and the desk is linked for every reader (#366)
/portal returned 404. The member portal is the desk at /account, so
/portal, /portal/* and /desk now redirect there (temporary, so a portal
page of its own can take the address back).

The top bar's Desk link and the palette's Desk row were shown only to a
signed-in reader, so nobody without a session could find it. Signed out,
/account already says what the desk is and offers sign-in; both now show
for everyone.


Claude-Session: https://claude.ai/code/session_019MDtmuvTGrpo3VChP3skH8

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-12 05:05:07 +01:00

77 lines
2.4 KiB
TypeScript

/**
* What the command palette offers before the search index answers: every
* destination the site has, in one list, so the long tail does not need a row
* in the sidebar to be one keystroke away.
*
* Pure, so `test/nav.test.ts` can hold it to "every nav path is in the
* palette" without a browser.
*/
import { createSearch, type Hit, type SearchSpec } from '@bitbaum/searchkit';
import {
ACCOUNT_NAV,
FOOTER_NAV,
HOME_LINK,
NAV_SECTIONS,
PALETTE_EXTRA,
READER_VIEWS,
type NavLink,
} from '@/config/site-nav';
export interface PaletteEntry {
key: string;
label: string;
hint: string;
href: string;
/** Where it sits, shown beside the label: "Explore", "For you", "Account". */
group: string;
}
function entries(group: string, links: readonly NavLink[]): PaletteEntry[] {
return links.map((l) => ({ key: `${group}:${l.href}`, group, ...l }));
}
export function paletteEntries({
signedIn,
reviewer,
}: {
signedIn: boolean;
reviewer: boolean;
}): PaletteEntry[] {
// The desk is offered to everyone: signed out, it says what it is and how
// to sign in. Settings and the inbox need a session.
const account = signedIn
? [ACCOUNT_NAV.desk, ACCOUNT_NAV.settings, ...(reviewer ? [ACCOUNT_NAV.inbox] : [])]
: [ACCOUNT_NAV.desk];
const all = [
...entries('Account', account),
...entries('Home', [HOME_LINK]),
...NAV_SECTIONS.flatMap((s) => entries(s.label, s.items)),
...entries('For you', READER_VIEWS),
...entries('Data', PALETTE_EXTRA),
...entries('About', FOOTER_NAV),
];
// One row per destination, even where two lists share a page.
return all.filter((e, i) => all.findIndex((o) => o.href === e.href) === i);
}
/** The label first, then where it sits and the one-line hint. */
const SPEC: SearchSpec<PaletteEntry> = {
fields: [
{ name: 'label', get: (e) => e.label },
{ name: 'hint', get: (e) => [e.group, e.hint] },
],
};
/**
* The pages matching what was typed, best first, forgiving a slip ("expsoure"
* is still Exposure), with the ranges to mark in each label.
*/
export function searchEntries(list: readonly PaletteEntry[], query: string): Hit<PaletteEntry>[] {
return createSearch(list, SPEC).search(query);
}
export function filterEntries(list: readonly PaletteEntry[], query: string): PaletteEntry[] {
return query.trim() ? searchEntries(list, query).map((h) => h.item) : [...list];
}