Files
paseo/packages/website/src/server-entry.ts
Mohamed Boudra 7e46f6a647 Rework docs navigation and move alternatives to top-level pages (#1487)
* Rework docs navigation and move alternatives to top-level pages

- Add nested docs nav with categories, collapsible groups, breadcrumbs,
  and a right-hand page outline with heading slugs.
- Move alternatives out of /docs/alternatives into /alternatives/*
  marketing pages with 301 redirects.
- Add github-slugger for heading IDs and require explicit width on
  SiteShell so new pages can't accidentally pick the narrow prose layout.
- Remove the best-practices doc from public-docs.

* Make docs content column prose-width
2026-06-12 12:53:30 +00:00

56 lines
1.7 KiB
TypeScript

import startEntry from "@tanstack/react-start/server-entry";
import { getDoc } from "~/docs";
import { buildLlmsTxt } from "~/llms";
const CANONICAL_HOST = "paseo.sh";
type FetchArgs = Parameters<typeof startEntry.fetch>;
function markdownResponse(body: string): Response {
return new Response(body, {
headers: {
"content-type": "text/markdown; charset=utf-8",
"cache-control": "public, max-age=300, s-maxage=300",
},
});
}
function docSlugFromMarkdownPath(pathname: string): string | null {
if (pathname === "/docs.md") return "";
const match = pathname.match(/^\/docs\/(.+)\.md$/);
return match ? match[1] : null;
}
export default {
async fetch(...args: FetchArgs): Promise<Response> {
const [request] = args;
const url = new URL(request.url);
const isLocal = url.hostname === "localhost" || url.hostname === "127.0.0.1";
if (!isLocal && (url.hostname !== CANONICAL_HOST || url.protocol !== "https:")) {
url.protocol = "https:";
url.hostname = CANONICAL_HOST;
return Response.redirect(url.toString(), 301);
}
const altRedirectMatch = url.pathname.match(/^\/docs\/alternatives\/(.+?)\/?$/);
if (altRedirectMatch) {
url.pathname = `/alternatives/${altRedirectMatch[1]}`;
return Response.redirect(url.toString(), 301);
}
if (url.pathname === "/llms.txt") {
return markdownResponse(buildLlmsTxt());
}
const slug = docSlugFromMarkdownPath(url.pathname);
if (slug !== null) {
const doc = getDoc(slug);
if (!doc) return new Response("Not found", { status: 404 });
return markdownResponse(doc.content);
}
return startEntry.fetch(...args);
},
};