Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/docs/app/llms.mdx/[[...slug]]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { getLLMText } from "@/loaders/get-llm-text";
import { source } from "@/loaders/source";
import { notFound } from "next/navigation";

export const revalidate = false;

export async function GET(_req: Request, { params }: { params: Promise<{ slug?: string[] }> }) {
const { slug } = await params;
const page = source.getPage(slug);
if (!page) notFound();

return new Response(await getLLMText(page), {
headers: {
"Content-Type": "text/markdown; charset=utf-8",
},
});
}

export function generateStaticParams() {
return source.generateParams();
}
23 changes: 23 additions & 0 deletions packages/docs/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { isMarkdownPreferred, rewritePath } from "fumadocs-core/negotiation";
import { type NextRequest, NextResponse } from "next/server";

const { rewrite: rewriteLLM } = rewritePath("/*path", "/llms.mdx/*path");

export function middleware(request: NextRequest) {
const pathname = request.nextUrl.pathname;

// Handle content negotiation via Accept header
if (isMarkdownPreferred(request)) {
const result = rewriteLLM(pathname);

if (result) {
return NextResponse.rewrite(new URL(result, request.nextUrl));
}
}

return NextResponse.next();
}

export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
};
34 changes: 23 additions & 11 deletions packages/docs/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ function generateRedirects(idmap, page, origin = "/") {
/** @type {import('next').NextConfig} */
const config = {
reactStrictMode: true,
async rewrites() {
return [
{
source: "/:path*.md{x}?",
destination: "/llms.mdx/:path*",
},
];
},
redirects() {
const mainPageRedirects = [
// INTRO
Expand All @@ -52,7 +60,7 @@ const config = {
requirements: "requirements",
"from-npm": "installation",
},
"/"
"/",
),

// ECOSYSTEM
Expand All @@ -68,7 +76,7 @@ const config = {
"powered-by-zod": "powered-by-zod",
"utilities-for-zod": "zod-utilities",
},
"/ecosystem"
"/ecosystem",
),

// BASIC USAGE
Expand All @@ -82,7 +90,7 @@ const config = {
safeparse: "handling-errors",
safeparseasync: "handling-errors",
},
"/basics"
"/basics",
),

// API
Expand Down Expand Up @@ -173,15 +181,15 @@ const config = {
readonly: "readonly",
pipe: "pipes",
},
"/api"
"/api",
),

// METADATA
...generateRedirects(
{
describe: "",
},
"/metadata"
"/metadata",
),

// FOR MAINTAINERS
Expand All @@ -191,7 +199,7 @@ const config = {
"inferring-the-inferred-type": "how-to-accept-user-defined-schemas",
"constraining-allowable-inputs": "how-to-accept-user-defined-schemas",
},
"/library-authors"
"/library-authors",
),

// FORMATTING ERRORS
Expand All @@ -200,14 +208,14 @@ const config = {
{
"error-formatting": "",
},
"/error-formatting"
"/error-formatting",
),

...generateRedirects(
{
"error-handling": "handling-errors",
},
"/basics"
"/basics",
),

// DROPPED
Expand Down Expand Up @@ -238,7 +246,7 @@ const config = {
zodparsedtype: "",
},
"/error-customization",
"/ERROR_HANDLING"
"/ERROR_HANDLING",
),
...generateRedirects(
{
Expand All @@ -248,7 +256,7 @@ const config = {
"flattening-errors": "zflattenerror",
},
"/error-formatting",
"/ERROR_HANDLING"
"/ERROR_HANDLING",
),
];

Expand All @@ -261,7 +269,11 @@ const config = {
},
];

const redirects = [...mainPageRedirects, ...errorHandlingRedirects, ...changelogRedirects];
const redirects = [
...mainPageRedirects,
...errorHandlingRedirects,
...changelogRedirects,
];
return redirects;
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@radix-ui/react-accordion": "^1.2.4",
"@vercel/analytics": "^1.5.0",
"@vercel/og": "^0.6.8",
"fumadocs-core": "15.1.0",
"fumadocs-core": "15.8.3",
"fumadocs-mdx": "11.5.6",
"fumadocs-ui": "15.1.0",
"gray-matter": "^4.0.3",
Expand Down
Loading