From ade3442b71fefa71672784b397045806f4ad0626 Mon Sep 17 00:00:00 2001 From: kxndrick0 Date: Thu, 20 Feb 2025 18:27:39 -0600 Subject: [PATCH 1/3] code visualization --- web/src/pages/[func].astro | 26 +++++++++++++++++++++++++- web/src/utils/functions.ts | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/web/src/pages/[func].astro b/web/src/pages/[func].astro index b155956d..e4efce4c 100644 --- a/web/src/pages/[func].astro +++ b/web/src/pages/[func].astro @@ -3,6 +3,9 @@ import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro'; import { getCollection } from 'astro:content'; import { getFunctionInfo } from '@src/utils/functions'; import { marked } from 'marked'; +import fs from "fs"; +import path from "path"; +import { Code } from '@astrojs/starlight/components'; export async function getStaticPaths() { const functions = await getCollection('functions'); @@ -15,11 +18,24 @@ export async function getStaticPaths() { const { func } = Astro.props; const funcInfo = getFunctionInfo(func.data); - const funcType = funcInfo.type; const funcTypePretty = funcInfo.typePretty; const funcPair = funcInfo.pair; +const funcPath = path.dirname(func.filePath ?? "") +let funcExamples = funcInfo.examples + +if ( funcExamples.length > 0 ){ + funcExamples = funcInfo.examples.map((example: any) => { + try { + const luaCode = fs.readFileSync(path.resolve(`${funcPath}`, example.path), "utf8"); + return { ...example, luaCode }; + } catch (error) { + console.error(`Error reading ${example.path}:`, error); + return { ...example, luaCode: "Loading example error." }; + } + }); +} --- + + {funcExamples.length > 0 && funcExamples.map((example: any) => ( +
+

+ +
+ ))} +
diff --git a/web/src/utils/functions.ts b/web/src/utils/functions.ts index f084c281..0ed9c837 100644 --- a/web/src/utils/functions.ts +++ b/web/src/utils/functions.ts @@ -36,6 +36,7 @@ export function getFunctionInfo(data: FunctionData): any { type: getFunctionType(data), typePretty: getFunctionTypePretty(data), pair: data.shared?.pair || data.client?.pair || data.server?.pair || false, + examples: data.shared?.examples || data.client?.examples || data.server?.examples || [ ], }; } From ccde14ffea45979e52739814ac2e27a4951241b1 Mon Sep 17 00:00:00 2001 From: kxndrick0 Date: Sat, 22 Feb 2025 02:17:52 -0600 Subject: [PATCH 2/3] add more pagination buttons --- web/src/overrides/Pagination.astro | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/web/src/overrides/Pagination.astro b/web/src/overrides/Pagination.astro index ea34f999..f49dd37c 100644 --- a/web/src/overrides/Pagination.astro +++ b/web/src/overrides/Pagination.astro @@ -15,9 +15,26 @@ import IconLinkCard from '@src/components/IconLinkCard.astro'; title="Forum" description="Engage with the community in the old-fashioned way." href="https://forum.multitheftauto.com/" /> - + + + + + + Date: Sat, 22 Feb 2025 02:31:20 -0600 Subject: [PATCH 3/3] fix tab --- web/src/overrides/Pagination.astro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/overrides/Pagination.astro b/web/src/overrides/Pagination.astro index f49dd37c..b3f017b7 100644 --- a/web/src/overrides/Pagination.astro +++ b/web/src/overrides/Pagination.astro @@ -16,7 +16,7 @@ import IconLinkCard from '@src/components/IconLinkCard.astro'; description="Engage with the community in the old-fashioned way." href="https://forum.multitheftauto.com/" /> -