diff --git a/packages/website-ue/src/content.config.ts b/packages/website-ue/src/content.config.ts new file mode 100644 index 000000000..9eeea3421 --- /dev/null +++ b/packages/website-ue/src/content.config.ts @@ -0,0 +1,38 @@ +import { glob } from "astro/loaders"; +import { z } from "astro/zod"; +import { defineCollection } from "astro:content"; + +const api = defineCollection({ + loader() { + const globbed = import.meta.glob("./pages/api/**/*.ts", { + eager: true, + query: "?raw", + import: "default", + }); + + const paths: { id: string; body: 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].spl; + + paths.push({ id, body, docs: docs?.[1] ?? undefined }); + } + + return paths; + }, + + schema: z.object({ + body: z.string(), + docs: z.optional(z.string()), + }), +}); + +const docs = defineCollection({ + loader: glob({ base: "../../docs", pattern: "**/*.md" }), +}); + +export const collections = { api, docs }; diff --git a/packages/website-ue/src/pages/[...locale]/api/index.astro b/packages/website-ue/src/pages/[...locale]/api/index.astro index 9ee4af5f2..225510a95 100644 --- a/packages/website-ue/src/pages/[...locale]/api/index.astro +++ b/packages/website-ue/src/pages/[...locale]/api/index.astro @@ -1,61 +1,32 @@ --- import "@radix-ui/colors/amber-dark.css"; -import { - createProgram, - displayPartsToString, - forEachChild, - isFunctionDeclaration, -} from "typescript"; +import { getCollection } from "astro:content"; import BaseLayout from "../../../layouts/BaseLayout.astro"; export { getStaticPaths } from "../index.astro"; const { locale } = Astro.props; -const root = `/src/pages/api`; -const globbed = import.meta.glob("/src/pages/api/**/*", { - eager: true, - query: "?raw", - import: "default", -}); +const collection = await getCollection("api"); + +console.log(collection); + const paths: { path: string; documentation: string; }[] = []; -for (const fullPath in globbed) { - const relativePath = `.${fullPath}`; - const path = fullPath.slice(root.length + 1, -3); - const program = createProgram([relativePath], {}); - const source = program.getSourceFile(relativePath); - if (!source) throw new Error(`Could not find source for ${fullPath}`); - - const checker = program.getTypeChecker(); - - const getter = forEachChild(source, (node) => { - if (!isFunctionDeclaration(node) || node.name?.text !== "GET") return; - return checker.getSymbolAtLocation(node.name); - }); - - const documentationComment = getter?.getDocumentationComment(checker); - if (!documentationComment) continue; - - const documentation = displayPartsToString(documentationComment); - if (documentation.length === 0) continue; - - paths.push({ path, documentation }); -} - paths.sort((a, b) => a.path.localeCompare(b.path)); --- - +

api

{ - paths.map(({ path, documentation }) => ( + collection.map(({ id, data }) => ( <> -

{path}

-
{documentation}
+

{id}

+
{data.docs}
+
{data.body}
)) } diff --git a/packages/website-ue/src/pages/api/avatars/[id].json.ts b/packages/website-ue/src/pages/api/avatars/[id].json.ts index 679e47a5e..2520b8d51 100644 --- a/packages/website-ue/src/pages/api/avatars/[id].json.ts +++ b/packages/website-ue/src/pages/api/avatars/[id].json.ts @@ -9,6 +9,16 @@ export const getStaticPaths = (async () => { })); }) satisfies GetStaticPaths; +/** + * This is a very long. + * And boring. + * + * But important. + * Developer comment. + * + * Meant to test. + * The **formatting**! + */ export async function GET({ params }: APIContext) { const avatar = await api.avatar(params.id); return Response.json(avatar); diff --git a/tsconfig.json b/tsconfig.json index faa4c5f5d..7d6c174bf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,7 +16,8 @@ "isolatedModules": true, "paths": { "@protos/*": ["./packages/closed/protos/*"] - } + }, + "strictNullChecks": true }, "exclude": ["node_modules/**/*", "dist"] }