diff --git a/app/llms.txt/route.ts b/app/llms.txt/route.ts new file mode 100644 index 0000000..761ae00 --- /dev/null +++ b/app/llms.txt/route.ts @@ -0,0 +1,34 @@ +import { source } from '@/lib/source'; +import { siteConfig } from '@/lib/config'; +import { llms } from 'fumadocs-core/source/llms'; + +export const dynamic = 'force-static'; + +const generator = llms(source); + +export function GET() { + const index = generator + .index() + // The shared loader must keep site-relative URLs for the app's own routing, + // so the generated index is absolutized here instead — agents fetch this + // file standalone, with no base URL to resolve against. + .replaceAll('](/', `](${siteConfig.url}/`) + // llms.txt expects a single H1 (ours, below); demote the generator's root + // heading by position rather than by literal text. + .replace(/^# /m, '## '); + + const body = [ + '# Next Commerce Merchant Documentation', + '', + '> Merchant documentation for Next Commerce (NEXT), an ecommerce platform for direct-to-consumer brands and performance marketers — storefronts, orders, subscriptions, payments, fulfillment, apps, and analytics.', + '', + `Related resources: [Developer Docs](https://developers.nextcommerce.com/) (APIs, themes, campaigns), [Platform Changelog](${siteConfig.url}/changelog), [nextcommerce.com](https://nextcommerce.com) (product and pricing).`, + '', + index, + '', + ].join('\n'); + + return new Response(body, { + headers: { 'Content-Type': 'text/plain; charset=utf-8' }, + }); +} diff --git a/lib/config.ts b/lib/config.ts index c666225..1f05ced 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -1,5 +1,9 @@ export const siteConfig = { companyName: 'Next Commerce', + // Canonical origin for absolute links in machine-readable outputs (llms.txt). + // Must match the route in wrangler.jsonc. No trailing slash — consumers + // concatenate `/${path}` onto this value. + url: 'https://docs.nextcommerce.com', githubOrg: 'NextCommerceCo', githubRepo: 'docs', get githubUrl() {