Skip to content

The Open Standard for Generative UI

fix(docs): harden GEO discovery endpoints (#852)

Zahle Khanc4409d368f99
diff --git a/docs/app/llms-full.txt/route.ts b/docs/app/llms-full.txt/route.ts
index fcccaeefa..43b99e65a 100644
--- a/docs/app/llms-full.txt/route.ts
+++ b/docs/app/llms-full.txt/route.ts
@@ -1,10 +1,16 @@
import { getLLMText, source } from "@/lib/source";
+export const dynamic = "force-static";
export const revalidate = false;
export async function GET() {
const scan = source.getPages().map(getLLMText);
const scanned = await Promise.all(scan);
- return new Response(scanned.join("\n\n"));
+ return new Response(scanned.join("\n\n"), {
+ headers: {
+ "Content-Type": "text/plain; charset=utf-8",
+ "X-Robots-Tag": "noindex, follow",
+ },
+ });
}
diff --git a/docs/app/llms.mdx/docs/[[...slug]]/route.ts b/docs/app/llms.mdx/docs/[[...slug]]/route.ts
index 6019bc8c4..216eada31 100644
--- a/docs/app/llms.mdx/docs/[[...slug]]/route.ts
+++ b/docs/app/llms.mdx/docs/[[...slug]]/route.ts
@@ -1,16 +1,20 @@
-import { getLLMText, source } from "@/lib/source";
+import { BASE_URL, getLLMText, source } from "@/lib/source";
import { notFound } from "next/navigation";
+export const dynamic = "force-static";
+export const dynamicParams = false;
export const revalidate = false;
export async function GET(_req: Request, { params }: RouteContext<"/llms.mdx/docs/[[...slug]]">) {
const { slug } = await params;
const page = source.getPage(slug);
if (!page) notFound();
+ const canonicalUrl = new URL(page.url, BASE_URL).toString();
return new Response(await getLLMText(page), {
headers: {
- "Content-Type": "text/markdown",
+ "Content-Type": "text/markdown; charset=utf-8",
+ Link: `<${canonicalUrl}>; rel="canonical"`,
},
});
}
diff --git a/docs/app/llms.txt/route.ts b/docs/app/llms.txt/route.ts
index cc98a1c3a..1682b23f6 100644
--- a/docs/app/llms.txt/route.ts
+++ b/docs/app/llms.txt/route.ts
@@ -1,13 +1,43 @@
-import { source } from "@/lib/source";
+import { BASE_URL, source } from "@/lib/source";
+export const dynamic = "force-static";
export const revalidate = false;
+const SITE_DESCRIPTION =
+ "Full-stack, renderer-agnostic Generative UI with a streaming-first language, official React support, community integrations, and up to 67% fewer tokens than JSON.";
+
export async function GET() {
- const lines: string[] = [];
- lines.push("# Documentation");
- lines.push("");
- for (const page of source.getPages()) {
- lines.push(`- [${page.data.title}](${page.url}): ${page.data.description}`);
- }
- return new Response(lines.join("\n"));
+ const pages = source.getPages().map((page) => {
+ const canonicalUrl = new URL(page.url, BASE_URL);
+ const markdownUrl = new URL(`${page.url}.mdx`, BASE_URL);
+ const description = page.data.description || `OpenUI documentation for ${page.data.title}.`;
+
+ return `- [${page.data.title}](${markdownUrl}): ${description} Canonical source: ${canonicalUrl}`;
+ });
+
+ const index = [
+ "# OpenUI",
+ "",
+ `> ${SITE_DESCRIPTION}`,
+ "",
+ "## Project",
+ "",
+ `- [OpenUI website](${new URL("/", BASE_URL)}): Canonical OpenUI website.`,
+ "- [OpenUI source repository](https://github.com/thesysdev/openui): Source code and releases.",
+ "",
+ "## Documentation",
+ "",
+ ...pages,
+ "",
+ "## Optional",
+ "",
+ `- [Complete OpenUI documentation](${new URL("/llms-full.txt", BASE_URL)}): Full documentation in one plain-text response; it may exceed an LLM context window.`,
+ "",
+ ].join("\n");
+
+ return new Response(index, {
+ headers: {
+ "Content-Type": "text/plain; charset=utf-8",
+ },
+ });
}
diff --git a/docs/lib/source.ts b/docs/lib/source.ts
index bef5cc7e3..5edcb0c88 100644
--- a/docs/lib/source.ts
+++ b/docs/lib/source.ts
@@ -28,8 +28,15 @@ export function getPageImage(page: InferPageType<typeof source>) {
export async function getLLMText(page: InferPageType<typeof source>) {
const processed = await page.data.getText("processed");
+ const description = page.data.description || `OpenUI documentation for ${page.data.title}.`;
+ const canonicalUrl = new URL(page.url, BASE_URL);
return `# ${page.data.title}
-${processed}`;
+> ${description}
+
+Source: ${canonicalUrl}
+
+${processed.trim()}
+`;
}