Skip to content

Commit f4ba4d8

Browse files
authoredFeb 22, 2025··
Code display and more pagination buttons (#5)
1 parent 46c6b19 commit f4ba4d8

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed
 

‎web/src/overrides/Pagination.astro

+18-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,26 @@ import IconLinkCard from '@src/components/IconLinkCard.astro';
1515
title="Forum"
1616
description="Engage with the community in the old-fashioned way."
1717
href="https://forum.multitheftauto.com/" />
18-
</CardGrid>
1918

19+
<IconLinkCard
20+
icon="seti:powershell"
21+
title="Functions"
22+
description="List of all client-side, server-side and shared functions"
23+
href="/Scripting_Functions" />
2024

25+
<IconLinkCard
26+
icon="seti:purescript"
27+
title="Events"
28+
description="List of all client-side, server-side and shared events"
29+
href="/Scripting_Events" />
30+
31+
<IconLinkCard
32+
icon="seti:plan"
33+
title="Elements"
34+
description="List of MTA:SA elements"
35+
href="/Element_tree" />
36+
</CardGrid>
37+
2138
<IconLinkCard
2239
icon="github"
2340
title="GitHub Repository"

‎web/src/pages/[func].astro

+25-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
33
import { getCollection } from 'astro:content';
44
import { getFunctionInfo } from '@src/utils/functions';
55
import { marked } from 'marked';
6+
import fs from "fs";
7+
import path from "path";
8+
import { Code } from '@astrojs/starlight/components';
69
710
export async function getStaticPaths() {
811
const functions = await getCollection('functions');
@@ -15,11 +18,24 @@ export async function getStaticPaths() {
1518
const { func } = Astro.props;
1619
1720
const funcInfo = getFunctionInfo(func.data);
18-
1921
const funcType = funcInfo.type;
2022
const funcTypePretty = funcInfo.typePretty;
2123
2224
const funcPair = funcInfo.pair;
25+
const funcPath = path.dirname(func.filePath ?? "")
26+
let funcExamples = funcInfo.examples
27+
28+
if ( funcExamples.length > 0 ){
29+
funcExamples = funcInfo.examples.map((example: any) => {
30+
try {
31+
const luaCode = fs.readFileSync(path.resolve(`${funcPath}`, example.path), "utf8");
32+
return { ...example, luaCode };
33+
} catch (error) {
34+
console.error(`Error reading ${example.path}:`, error);
35+
return { ...example, luaCode: "Loading example error." };
36+
}
37+
});
38+
}
2339
---
2440

2541
<StarlightPage frontmatter={{
@@ -35,4 +51,12 @@ const funcPair = funcInfo.pair;
3551

3652
<!-- Description -->
3753
<Fragment set:html={marked(funcInfo.description)} />
54+
55+
{funcExamples.length > 0 && funcExamples.map((example: any) => (
56+
<div>
57+
<p set:html={marked(example.description)}></p>
58+
<Code code={example.luaCode} lang="lua" title={path.basename(example.path)} />
59+
</div>
60+
))}
61+
3862
</StarlightPage>

‎web/src/utils/functions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export function getFunctionInfo(data: FunctionData): any {
3636
type: getFunctionType(data),
3737
typePretty: getFunctionTypePretty(data),
3838
pair: data.shared?.pair || data.client?.pair || data.server?.pair || false,
39+
examples: data.shared?.examples || data.client?.examples || data.server?.examples || [ ],
3940
};
4041
}
4142

0 commit comments

Comments
 (0)
Please sign in to comment.