mirror of
https://github.com/trycua/computer.git
synced 2026-01-02 03:20:22 -06:00
Setup llms.txt & *.mdx routes
This commit is contained in:
@@ -5,7 +5,14 @@ const withMDX = createMDX();
|
||||
/** @type {import('next').NextConfig} */
|
||||
const config = {
|
||||
reactStrictMode: true,
|
||||
|
||||
async rewrites() {
|
||||
return [
|
||||
{
|
||||
source: '/home/:path*.mdx',
|
||||
destination: '/llms.mdx/:path*',
|
||||
},
|
||||
];
|
||||
},
|
||||
images: {
|
||||
dangerouslyAllowSVG: true,
|
||||
remotePatterns: [
|
||||
|
||||
@@ -18,17 +18,20 @@
|
||||
"next-themes": "^0.4.6",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0",
|
||||
"remark": "^15.0.1",
|
||||
"remark-gfm": "^4.0.1",
|
||||
"remark-mdx": "^3.1.0",
|
||||
"tailwind-merge": "^3.3.1",
|
||||
"zod": "^3.25.76"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "^3.6.2",
|
||||
"@tailwindcss/postcss": "^4.1.8",
|
||||
"@types/mdx": "^2.0.13",
|
||||
"@types/node": "22.15.28",
|
||||
"@types/react": "^19.1.6",
|
||||
"@types/react-dom": "^19.1.5",
|
||||
"postcss": "^8.5.4",
|
||||
"prettier": "^3.6.2",
|
||||
"tailwindcss": "^4.1.8",
|
||||
"typescript": "^5.8.3"
|
||||
},
|
||||
|
||||
9
docs/pnpm-lock.yaml
generated
9
docs/pnpm-lock.yaml
generated
@@ -35,6 +35,15 @@ importers:
|
||||
react-dom:
|
||||
specifier: ^19.1.0
|
||||
version: 19.1.0(react@19.1.0)
|
||||
remark:
|
||||
specifier: ^15.0.1
|
||||
version: 15.0.1
|
||||
remark-gfm:
|
||||
specifier: ^4.0.1
|
||||
version: 4.0.1
|
||||
remark-mdx:
|
||||
specifier: ^3.1.0
|
||||
version: 3.1.0
|
||||
tailwind-merge:
|
||||
specifier: ^3.3.1
|
||||
version: 3.3.1
|
||||
|
||||
21
docs/src/app/llms.mdx/[[...slug]]/route.ts
Normal file
21
docs/src/app/llms.mdx/[[...slug]]/route.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import { getLLMText } from '@/lib/llms';
|
||||
import { source } from '@/lib/source';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
export const revalidate = false;
|
||||
|
||||
export async function GET(
|
||||
_req: NextRequest,
|
||||
{ params }: { params: Promise<{ slug?: string[] }> }
|
||||
) {
|
||||
const { slug } = await params;
|
||||
const page = source.getPage(['home', ...slug!]);
|
||||
if (!page) notFound();
|
||||
|
||||
return new NextResponse(await getLLMText(page));
|
||||
}
|
||||
|
||||
export function generateStaticParams() {
|
||||
return source.generateParams();
|
||||
}
|
||||
12
docs/src/app/llms.txt/route.ts
Normal file
12
docs/src/app/llms.txt/route.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { source } from '@/lib/source';
|
||||
import { getLLMText } from '@/lib/llms';
|
||||
|
||||
// cached forever
|
||||
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'));
|
||||
}
|
||||
26
docs/src/lib/llms.ts
Normal file
26
docs/src/lib/llms.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { remark } from 'remark';
|
||||
import remarkGfm from 'remark-gfm';
|
||||
import remarkMdx from 'remark-mdx';
|
||||
import { remarkInclude } from 'fumadocs-mdx/config';
|
||||
import { source } from '@/lib/source';
|
||||
import type { InferPageType } from 'fumadocs-core/source';
|
||||
|
||||
const processor = remark()
|
||||
.use(remarkMdx)
|
||||
// needed for Fumadocs MDX
|
||||
.use(remarkInclude)
|
||||
.use(remarkGfm);
|
||||
|
||||
export async function getLLMText(page: InferPageType<typeof source>) {
|
||||
const processed = await processor.process({
|
||||
path: page.data._file.absolutePath,
|
||||
value: page.data.content,
|
||||
});
|
||||
|
||||
return `# ${page.data.title}
|
||||
URL: ${page.url}
|
||||
|
||||
${page.data.description}
|
||||
|
||||
${processed.value}`;
|
||||
}
|
||||
Reference in New Issue
Block a user