--- type Props = { name: string; }; import { readFile } from "node:fs/promises"; import Link from "./Link.astro"; import { codeToHtml } from "shiki"; import { transformerTwoslash, rendererClassic } from "@shikijs/twoslash"; import "@shikijs/twoslash/style-classic.css"; const { name } = Astro.props; const fileText = await readFile(`${process.cwd()}/problems/${name}.ts`); const tsCode = fileText.toString(); const cleanCode = tsCode .replaceAll("export type", "type") .replaceAll("// ^?", "// ^?"); const html = await codeToHtml(cleanCode, { lang: "ts", theme: "vitesse-dark", transformers: [ transformerTwoslash({ renderer: rendererClassic(), }), ], }); let title = name .split("-") .map((s) => s.charAt(0).toUpperCase() + s.slice(1)) .join(" "); let isOnLeetCode = false; try { const req = await fetch("https://leetcode.com/graphql/", { method: "POST", body: JSON.stringify({ query: `\n query questionTitle($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n questionId\n questionFrontendId\n title\n titleSlug\n isPaidOnly\n difficulty\n likes\n dislikes\n categoryTitle\n }\n}\n`, variables: { titleSlug: name, }, operationName: "questionTitle", }), headers: { "Content-Type": "application/json", }, }); const json = await req.json(); if (json?.data?.question?.title) { title = json.data.question.title; isOnLeetCode = true; } } catch (e) { console.log("error fetching title", e); } const leetCodeUrl = `https://leetcode.com/problems/${name}`; ---