Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion web/src/overrides/Pagination.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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/" />
</CardGrid>

<IconLinkCard
icon="seti:powershell"
title="Functions"
description="List of all client-side, server-side and shared functions"
href="/Scripting_Functions" />

<IconLinkCard
icon="seti:purescript"
title="Events"
description="List of all client-side, server-side and shared events"
href="/Scripting_Events" />

<IconLinkCard
icon="seti:plan"
title="Elements"
description="List of MTA:SA elements"
href="/Element_tree" />
</CardGrid>

<IconLinkCard
icon="github"
title="GitHub Repository"
Expand Down
26 changes: 25 additions & 1 deletion web/src/pages/[func].astro
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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." };
}
});
}
---

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

<!-- Description -->
<Fragment set:html={marked(funcInfo.description)} />

{funcExamples.length > 0 && funcExamples.map((example: any) => (
<div>
<p set:html={marked(example.description)}></p>
<Code code={example.luaCode} lang="lua" title={path.basename(example.path)} />
</div>
))}

</StarlightPage>
1 change: 1 addition & 0 deletions web/src/utils/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [ ],
};
}

Expand Down