* feat(website): nest docs pages under landable groups The docs sidebar could already render groups from subdirectories in public-docs, but nothing used it because every doc was a flat file, and two things stopped it being usable. A group had no page of its own, so its label was only a toggle and its name came from the directory name via formatLabel. A directory's index.md now supplies the group's label, order, and href, which makes the group landable and lets the label be authored rather than derived. Categories and top-level directories named the same thing, so a categorised doc at hub/index.md produced a group nested inside its own category. Only directories below the top level become groups now. Also fixes two behaviours in the sidebar: - The open/closed effect assigned containsActive on every change, so a group you expanded to browse collapsed the moment you navigated anywhere else. Navigating in now opens a group and navigating away leaves it alone. - The sidebar scrolls independently of the page and never scrolled the active entry into view, so loading or refreshing a page far down the list left the sidebar parked at the top with no visible position. The group row is a single target: it navigates and expands, and collapses when clicked again from the page it points at. A separate chevron button would put two actions a few pixels apart. * docs(hub): document Hub Adds a Hub section covering what it is, how it works, daemons, triggers, configuration, activity, and the two ways to run it. The section separates using Hub from running it. Overview, quickstart, daemons, triggers, and configuration hold regardless of who operates the deployment; the self-hosting branch owns deploying the service and creating the GitHub, Slack, and Discord apps it talks to. That split falls on a real seam, because those apps are exactly what a hosted Hub would own on your behalf. Hosted is a placeholder until it ships. Each provider gets a trigger page carrying its events, filter semantics, and the full paseo.event.* reference for the data a prompt can read. That data is the thing a config author actually needs and the thing they cannot get from anywhere else. Every YAML block was parsed against the Hub config schema rather than eyeballed, which kept several plausible-looking things out of the docs: worktree prNumber takes a literal number and not a merge variable, only daemon environments run today, and github.push has no actor so it can never satisfy the required from_users filter. Troubleshooting moves to order 90 so it stays last. * refactor(website): let the active docs entry scroll itself into view The layout queried the sidebar for the active entry after every navigation, which coupled it to when that entry mounts. A link inside a collapsed group only mounts once the group's own effect opens it, so the query could run against a DOM that does not contain it yet. Moving the scroll to the entry removes the ordering question rather than answering it, and drops the ref and the cross-component query. Reported by Greptile on #2864. The failure it described does not reproduce: navigating from a page outside a collapsed group into one of its children still scrolls correctly, verified with the group confirmed collapsed and the sidebar forced to the top. The coupling was real even though the bug was not. * docs(hub): stop listing BETTER_AUTH_URL as required It falls back to PASEO_CLOUD_PUBLIC_URL, so a deployment that sets the public origin already has a correct auth base URL. Listing it as required made the Fly recipe look incomplete when it was not. Moved to optional with its default, and recorded what actually breaks without BETTER_AUTH_SECRET: the auth routes close and nobody can sign in. Reported by Codex on #2864, which read the same inconsistency the other way round and proposed adding the variable to the Fly example. * docs(hub): attach a database in the Fly recipe The Fly section showed inline config and a secrets command, neither of which supplied DATABASE_URL. It defaults to localhost:5432, which on Fly reaches nothing, so the documented deployment could not start. fly postgres attach sets DATABASE_URL as a secret, so the step is the attach itself rather than another variable to copy. Reported by Codex on #2864. * docs: align Hub self-hosting contract
208 lines
6.1 KiB
TypeScript
208 lines
6.1 KiB
TypeScript
import { Link, useLocation } from "@tanstack/react-router";
|
|
import { ChevronDown, ChevronRight } from "lucide-react";
|
|
import { type MouseEvent, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
import { type DocsNavNode } from "~/docs";
|
|
|
|
interface DocsNavProps {
|
|
nodes: DocsNavNode[];
|
|
mobile?: boolean;
|
|
onNavigate?: () => void;
|
|
}
|
|
|
|
const ACTIVE_OPTIONS_EXACT = { exact: true };
|
|
|
|
function nodeContainsHref(node: DocsNavNode, href: string): boolean {
|
|
if (node.type === "page") return node.href === href;
|
|
if (node.type === "group" && node.href === href) return true;
|
|
return node.children.some((child) => nodeContainsHref(child, href));
|
|
}
|
|
|
|
function clsx(...classes: (string | false | null | undefined)[]): string {
|
|
return classes.filter(Boolean).join(" ");
|
|
}
|
|
|
|
/**
|
|
* The sidebar scrolls independently of the page, so the active entry has to
|
|
* bring itself into view. The entry owns this rather than the layout, because
|
|
* a link inside a collapsed group only mounts once that group opens, and
|
|
* anything watching from above would have to query before that happens.
|
|
*/
|
|
function useScrollIntoViewWhenActive(isActive: boolean) {
|
|
const ref = useRef<HTMLAnchorElement>(null);
|
|
|
|
useEffect(() => {
|
|
if (isActive) ref.current?.scrollIntoView({ block: "nearest" });
|
|
}, [isActive]);
|
|
|
|
return ref;
|
|
}
|
|
|
|
function PageLink({
|
|
node,
|
|
mobile,
|
|
onNavigate,
|
|
}: {
|
|
node: Extract<DocsNavNode, { type: "page" }>;
|
|
mobile?: boolean;
|
|
onNavigate?: () => void;
|
|
}) {
|
|
const location = useLocation();
|
|
const isActive = location.pathname === node.href;
|
|
const ref = useScrollIntoViewWhenActive(isActive);
|
|
|
|
return (
|
|
<Link
|
|
ref={ref}
|
|
to={node.href}
|
|
activeOptions={ACTIVE_OPTIONS_EXACT}
|
|
onClick={onNavigate}
|
|
data-docs-nav-active={isActive ? "" : undefined}
|
|
className={clsx(
|
|
"block px-3 py-2 text-sm rounded-md transition-colors",
|
|
mobile
|
|
? "text-muted-foreground hover:text-foreground"
|
|
: "text-muted-foreground hover:text-foreground hover:bg-muted",
|
|
isActive && (mobile ? "text-foreground" : "bg-muted text-foreground"),
|
|
)}
|
|
>
|
|
{node.label}
|
|
</Link>
|
|
);
|
|
}
|
|
|
|
function GroupNode({
|
|
node,
|
|
mobile,
|
|
onNavigate,
|
|
}: {
|
|
node: Extract<DocsNavNode, { type: "group" }>;
|
|
mobile?: boolean;
|
|
onNavigate?: () => void;
|
|
}) {
|
|
const location = useLocation();
|
|
const currentHref = location.pathname;
|
|
const containsActive = useMemo(() => nodeContainsHref(node, currentHref), [node, currentHref]);
|
|
const isActive = node.href === currentHref;
|
|
const ref = useScrollIntoViewWhenActive(isActive);
|
|
const [isOpen, setIsOpen] = useState(containsActive);
|
|
const toggle = useCallback(() => setIsOpen((open) => !open), []);
|
|
|
|
// Navigating into a group opens it. Navigating away must not close it, or a
|
|
// group you opened to browse collapses the moment you click something else.
|
|
useEffect(() => {
|
|
if (containsActive) setIsOpen(true);
|
|
}, [containsActive]);
|
|
|
|
// The row is one target: it takes you to the group's page and opens it.
|
|
// Clicking it again once you are already there collapses it.
|
|
const handleClick = useCallback(
|
|
(event: MouseEvent<HTMLAnchorElement>) => {
|
|
if (isActive) {
|
|
event.preventDefault();
|
|
toggle();
|
|
return;
|
|
}
|
|
setIsOpen(true);
|
|
onNavigate?.();
|
|
},
|
|
[isActive, onNavigate, toggle],
|
|
);
|
|
|
|
const hasChildren = node.children.length > 0;
|
|
const chevron = isOpen ? <ChevronDown size={14} /> : <ChevronRight size={14} />;
|
|
const rowClassName = clsx(
|
|
"w-full flex items-center justify-between gap-2 px-3 py-2 text-sm rounded-md transition-colors text-left",
|
|
mobile
|
|
? "text-muted-foreground hover:text-foreground"
|
|
: "text-muted-foreground hover:text-foreground hover:bg-muted",
|
|
containsActive && "text-foreground",
|
|
isActive && !mobile && "bg-muted",
|
|
);
|
|
|
|
return (
|
|
<div>
|
|
{node.href === undefined ? (
|
|
<button type="button" onClick={toggle} aria-expanded={isOpen} className={rowClassName}>
|
|
<span>{node.label}</span>
|
|
{hasChildren && chevron}
|
|
</button>
|
|
) : (
|
|
<Link
|
|
ref={ref}
|
|
to={node.href}
|
|
activeOptions={ACTIVE_OPTIONS_EXACT}
|
|
onClick={handleClick}
|
|
aria-expanded={hasChildren ? isOpen : undefined}
|
|
data-docs-nav-active={isActive ? "" : undefined}
|
|
className={rowClassName}
|
|
>
|
|
<span>{node.label}</span>
|
|
{hasChildren && chevron}
|
|
</Link>
|
|
)}
|
|
{isOpen && hasChildren && (
|
|
<div className="ml-3 pl-3 border-l border-border space-y-0.5">
|
|
<NavTree nodes={node.children} mobile={mobile} onNavigate={onNavigate} />
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function CategoryNode({
|
|
node,
|
|
mobile,
|
|
onNavigate,
|
|
}: {
|
|
node: Extract<DocsNavNode, { type: "category" }>;
|
|
mobile?: boolean;
|
|
onNavigate?: () => void;
|
|
}) {
|
|
return (
|
|
<div className={mobile ? "space-y-1" : "space-y-1 mt-6 first:mt-0"}>
|
|
<div className="px-3 py-2 text-xs font-medium text-foreground">{node.label}</div>
|
|
<NavTree nodes={node.children} mobile={mobile} onNavigate={onNavigate} />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function NavTree({ nodes, mobile, onNavigate }: DocsNavProps) {
|
|
return (
|
|
<div className="space-y-0.5">
|
|
{nodes.map((node) => {
|
|
if (node.type === "category") {
|
|
return (
|
|
<CategoryNode
|
|
key={`category-${node.label}`}
|
|
node={node}
|
|
mobile={mobile}
|
|
onNavigate={onNavigate}
|
|
/>
|
|
);
|
|
}
|
|
if (node.type === "group") {
|
|
return (
|
|
<GroupNode
|
|
key={`group-${node.segment}`}
|
|
node={node}
|
|
mobile={mobile}
|
|
onNavigate={onNavigate}
|
|
/>
|
|
);
|
|
}
|
|
return (
|
|
<PageLink key={`page-${node.href}`} node={node} mobile={mobile} onNavigate={onNavigate} />
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function DocsNav({ nodes, mobile, onNavigate }: DocsNavProps) {
|
|
return (
|
|
<div className={mobile ? undefined : "-ml-3"}>
|
|
<NavTree nodes={nodes} mobile={mobile} onNavigate={onNavigate} />
|
|
</div>
|
|
);
|
|
}
|