feat: proper api

This commit is contained in:
TrèsAbhi committed 2026-02-01 00:14:58 -06:00
1 parent ba6a83a9cb
commit 015d457d23
3 files changed
+9 -12

No files matched your search

+4 -6
View File
@@ -10,29 +10,27 @@ const api = defineCollection({
import: "default", import: "default",
}); });
const paths: { id: string; body: string }[] = []; const paths: { id: string; docs: string }[] = [];
for (const path in globbed) { for (const path in globbed) {
const id = path.replace("./pages/api/", "").replace(".ts", ""); const id = path.replace("./pages/api/", "").replace(".ts", "");
const body = (globbed[path] as string).replaceAll("\r\n", "\n"); const body = (globbed[path] as string).replaceAll("\r\n", "\n");
const docs = body const docs = body
.match( .match(
/\/\*\*\n((( \*.*)\n)+) \*\/\nexport (async )?function GET\(/, /\/\*\*\n((( \*.*)\n)+) \*\/\nexport (async )?function GET\(/,
)?.[1] )?.[1]
.split("\n") .replaceAll(/^ \* ?/gm, "");
.map((line) => line.replace(/ \* ?/, ""))
.join("\n");
if (!docs) continue; if (!docs) continue;
paths.push({ id, body: docs }); paths.push({ id, docs });
} }
return paths; return paths;
}, },
schema: z.object({ schema: z.object({
body: z.string(),
docs: z.optional(z.string()), docs: z.optional(z.string()),
}), }),
}); });
@@ -1,7 +1,6 @@
--- ---
import "@radix-ui/colors/amber-dark.css"; import "@radix-ui/colors/amber-dark.css";
import { getCollection } from "astro:content"; import { getCollection } from "astro:content";
import { tools } from "../../../core/tools/tools";
import BaseLayout from "../../../layouts/BaseLayout.astro"; import BaseLayout from "../../../layouts/BaseLayout.astro";
export { getStaticPaths } from "../index.astro"; export { getStaticPaths } from "../index.astro";
@@ -9,8 +8,6 @@ export { getStaticPaths } from "../index.astro";
const { locale } = Astro.props; const { locale } = Astro.props;
const collection = await getCollection("api"); const collection = await getCollection("api");
console.log(collection);
const paths: { const paths: {
path: string; path: string;
documentation: string; documentation: string;
@@ -19,15 +16,14 @@ const paths: {
paths.sort((a, b) => a.path.localeCompare(b.path)); paths.sort((a, b) => a.path.localeCompare(b.path));
--- ---
<BaseLayout selectedTool={tools.api} {locale} accent="lime"> <BaseLayout {locale} accent="lime">
<h1>api</h1> <h1>api</h1>
{ {
collection.map(({ id, data }) => ( collection.map(({ id, data }) => (
<> <>
<h2>{id}</h2> <h2>{id}</h2>
<pre style="background-color: red;">{data.docs}</pre> <pre>{data.docs}</pre>
<pre>{data.body}</pre>
</> </>
)) ))
} }
@@ -4,6 +4,9 @@ import { api } from "../../../core/api/dynamic";
export { getStaticPaths } from "./[id].pb"; export { getStaticPaths } from "./[id].pb";
/** /**
* Even Noah can't save these animals.
* Even Noah can't save these animals.
* Even Noah can't save these animals.
* Even Noah can't save these animals. * Even Noah can't save these animals.
*/ */
export async function GET({ params }: APIContext<never, { id: string }>) { export async function GET({ params }: APIContext<never, { id: string }>) {