Skip to content

Commit b1b6960

Browse files
authored
docs: serve markdown to agents (medusajs#13915)
1 parent 66bbe39 commit b1b6960

File tree

11 files changed

+173
-75
lines changed

11 files changed

+173
-75
lines changed

www/apps/book/app/md-content/[...slug]/route.ts renamed to www/apps/book/app/md-content/[[...slug]]/route.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getCleanMd } from "docs-utils"
2-
import { existsSync } from "fs"
2+
import { existsSync, readFileSync } from "fs"
33
import { unstable_cache } from "next/cache"
44
import { notFound } from "next/navigation"
55
import { NextRequest, NextResponse } from "next/server"
@@ -16,7 +16,21 @@ type Params = {
1616
}
1717

1818
export async function GET(req: NextRequest, { params }: Params) {
19-
const { slug } = await params
19+
const { slug = ["/"] } = await params
20+
21+
if (slug[0] === "/") {
22+
const llmsFile = readFileSync(
23+
path.join(process.cwd(), "public", "llms.txt"),
24+
"utf-8"
25+
)
26+
27+
return new NextResponse(llmsFile, {
28+
headers: {
29+
"Content-Type": "text/markdown",
30+
},
31+
status: 200,
32+
})
33+
}
2034

2135
// keep this so that Vercel keeps the files in deployment
2236
const basePath = path.join(process.cwd(), "app")

www/apps/book/middleware.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

www/apps/book/next.config.mjs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,35 @@ const nextConfig = {
115115
transpilePackages: ["docs-ui"],
116116
async rewrites() {
117117
return {
118+
beforeFiles: [
119+
{
120+
source:
121+
"/:path((?!resources|api|ui|user-guide|cloud).*)index.html.md",
122+
destination: "/md-content/:path*",
123+
},
124+
{
125+
source: "/:path*",
126+
has: [
127+
{
128+
type: "header",
129+
key: "Accept",
130+
value: "text/markdown",
131+
},
132+
],
133+
destination: "/md-content/:path*",
134+
},
135+
{
136+
source: "/:path*",
137+
has: [
138+
{
139+
type: "header",
140+
key: "Accept",
141+
value: "text/plain",
142+
},
143+
],
144+
destination: "/md-content/:path*",
145+
},
146+
],
118147
fallback: [
119148
{
120149
source: "/resources",

www/apps/cloud/middleware.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

www/apps/cloud/next.config.mjs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,38 @@ const nextConfig = {
152152
permanent: true,
153153
},
154154
],
155+
rewrites: async () => {
156+
return {
157+
beforeFiles: [
158+
{
159+
source: "/:path*/index.html.md",
160+
destination: "/md-content/:path*",
161+
},
162+
{
163+
source: "/:path*",
164+
has: [
165+
{
166+
type: "header",
167+
key: "accept",
168+
value: "text/markdown",
169+
},
170+
],
171+
destination: "/md-content/:path*",
172+
},
173+
{
174+
source: "/:path*",
175+
destination: "/md-content/:path*",
176+
has: [
177+
{
178+
type: "header",
179+
key: "accept",
180+
value: "text/plain",
181+
},
182+
],
183+
},
184+
],
185+
}
186+
},
155187
}
156188

157189
const withBundleAnalyzer = bundleAnalyzer({

www/apps/resources/middleware.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

www/apps/resources/next.config.mjs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,38 @@ const nextConfig = {
286286
experimental: {
287287
optimizePackageImports: ["@medusajs/icons", "@medusajs/ui", "elkjs"],
288288
},
289+
rewrites: async () => {
290+
return {
291+
beforeFiles: [
292+
{
293+
source: "/:path*/index.html.md",
294+
destination: "/md-content/:path*",
295+
},
296+
{
297+
source: "/:path*",
298+
has: [
299+
{
300+
type: "header",
301+
key: "accept",
302+
value: "text/markdown",
303+
},
304+
],
305+
destination: "/md-content/:path*",
306+
},
307+
{
308+
source: "/:path*",
309+
destination: "/md-content/:path*",
310+
has: [
311+
{
312+
type: "header",
313+
key: "accept",
314+
value: "text/plain",
315+
},
316+
],
317+
},
318+
],
319+
}
320+
},
289321
}
290322

291323
const withBundleAnalyzer = bundleAnalyzer({

www/apps/ui/middleware.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

www/apps/ui/next.config.mjs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,38 @@ const nextConfig = {
141141
experimental: {
142142
optimizePackageImports: ["@medusajs/icons", "@medusajs/ui"],
143143
},
144+
rewrites: async () => {
145+
return {
146+
beforeFiles: [
147+
{
148+
source: "/:path*/index.html.md",
149+
destination: "/md-content/:path*",
150+
},
151+
{
152+
source: "/:path*",
153+
has: [
154+
{
155+
type: "header",
156+
key: "accept",
157+
value: "text/markdown",
158+
},
159+
],
160+
destination: "/md-content/:path*",
161+
},
162+
{
163+
source: "/:path*",
164+
destination: "/md-content/:path*",
165+
has: [
166+
{
167+
type: "header",
168+
key: "accept",
169+
value: "text/plain",
170+
},
171+
],
172+
},
173+
],
174+
}
175+
},
144176
}
145177

146178
const withBundleAnalyzer = bundleAnalyzer({

www/apps/user-guide/middleware.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)