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