Explorar o código

feat(docs): adding .md to docs pages shows raw markdown (#5823)

Ryan Vogel hai 2 meses
pai
achega
ad6a5e6157
Modificáronse 1 ficheiros con 18 adicións e 0 borrados
  1. 18 0
      packages/web/src/pages/[...slug].md.ts

+ 18 - 0
packages/web/src/pages/[...slug].md.ts

@@ -0,0 +1,18 @@
+import type { APIRoute } from "astro"
+import { getCollection } from "astro:content"
+
+export const GET: APIRoute = async ({ params }) => {
+  const slug = params.slug || "index"
+  const docs = await getCollection("docs")
+  const doc = docs.find((d) => d.id === slug)
+
+  if (!doc) {
+    return new Response("Not found", { status: 404 })
+  }
+
+  return new Response(doc.body, {
+    headers: {
+      "Content-Type": "text/plain; charset=utf-8",
+    },
+  })
+}