Skip to content

Commit 184c6f0

Browse files
WIP function page
1 parent 2d73b58 commit 184c6f0

File tree

6 files changed

+52
-43
lines changed

6 files changed

+52
-43
lines changed

web/astro.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default defineConfig({
2828
// Override some default components
2929
Pagination: './src/overrides/Pagination.astro',
3030
},
31+
customCss: [ './src/styles/custom.css' ],
3132
disable404Route: true,
3233
sidebar: [
3334
{

web/src/pages/Scripting_Events.astro

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,6 @@ import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
1111
TODO
1212
</StarlightPage>
1313

14-
<style>
15-
.side-shared {
16-
color: rgb(117, 117, 255);
17-
}
18-
.side-client {
19-
color: rgb(255, 50, 50);
20-
}
21-
.side-server {
22-
color: rgb(232, 115, 0);
23-
}
24-
</style>
25-
2614
<script>
2715
document.querySelectorAll('.side-type-color').forEach(el => {
2816
const type = el.textContent || '';
Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
3-
import { getFunctionsByCategory, getFunctionType } from '@src/utils/functions';
3+
import { getFunctionsByCategory, getFunctionInfo } from '@src/utils/functions';
44
55
const functionsByCategory = getFunctionsByCategory();
66
---
@@ -17,30 +17,10 @@ const functionsByCategory = getFunctionsByCategory();
1717
<summary>{category} functions</summary>
1818
<ul>
1919
{funcs.map(func => (
20-
<li><a href={`/${func.id}`}>{func.id}</a> (<span class="side-type-color">{getFunctionType(func.data)}</span>)</li>
20+
<li><a href={`/${func.id}`}>{func.id}</a> (<span class={"side-"+getFunctionInfo(func.data).type}>{getFunctionInfo(func.data).typePretty}</span>)</li>
2121
))}
2222
</ul>
2323
</details>
2424
</section>
2525
))}
2626
</StarlightPage>
27-
28-
<style>
29-
.side-shared {
30-
color: rgb(117, 117, 255);
31-
}
32-
.side-client {
33-
color: rgb(255, 50, 50);
34-
}
35-
.side-server {
36-
color: rgb(232, 115, 0);
37-
}
38-
</style>
39-
40-
<script>
41-
document.querySelectorAll('.side-type-color').forEach(el => {
42-
const type = el.textContent || '';
43-
el.classList.add(`side-${type.toLowerCase()}`);
44-
});
45-
46-
</script>

web/src/pages/[func].astro

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
33
import { getCollection } from 'astro:content';
4-
import { getFunctionType } from '@src/utils/functions';
4+
import { getFunctionInfo } from '@src/utils/functions';
55
66
export async function getStaticPaths() {
77
const functions = await getCollection('functions');
@@ -12,13 +12,26 @@ export async function getStaticPaths() {
1212
}
1313
1414
const { func } = Astro.props;
15+
16+
const funcInfo = getFunctionInfo(func.data);
17+
18+
const funcType = funcInfo.type;
19+
const funcTypePretty = funcInfo.typePretty;
20+
const funcTypeClass = `side-${funcType}`;
21+
22+
const funcPair = funcInfo.pair;
1523
---
24+
1625
<StarlightPage frontmatter={{
1726
template: 'doc',
1827
title: func.id,
1928
tableOfContents: false,
2029
}}>
21-
<div>
22-
{getFunctionType(func.data)}
23-
</div>
30+
<p><strong>Type:</strong> <span class={funcTypeClass}>{funcTypePretty}</span></p>
31+
32+
{funcPair && (
33+
<p>Pair: <a href={ funcPair }>{ funcPair }</a></p>
34+
)}
35+
36+
<p>{ funcInfo.description }</p>
2437
</StarlightPage>

web/src/styles/custom.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* Custom MTA Wiki CSS */
2+
3+
/* Styling for "Client-side / Server-side / Shared" */
4+
.side-shared {
5+
color: rgb(117, 117, 255);
6+
}
7+
.side-client {
8+
color: rgb(255, 50, 50);
9+
}
10+
.side-server {
11+
color: rgb(232, 115, 0);
12+
}

web/src/utils/functions.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,32 @@ type FunctionsByTypeByCategory = {
1212
server: FunctionsByCategory;
1313
};
1414

15-
type FunctionData = {
16-
shared?: object;
17-
client?: object;
18-
server?: object;
15+
export type FunctionData = {
16+
shared?: any;
17+
client?: any;
18+
server?: any;
1919
};
2020

21-
export function getFunctionType(data: FunctionData): 'shared' | 'client' | 'server' {
21+
function getFunctionType(data: FunctionData): 'shared' | 'client' | 'server' {
2222
if (data.shared) return 'shared';
2323
if (data.client) return 'client';
2424
return 'server';
2525
}
26+
function getFunctionTypePretty(data: FunctionData): string {
27+
const funcType = getFunctionType(data);
28+
if (funcType === 'shared') return 'Shared';
29+
if (funcType === 'client') return 'Client-side';
30+
return 'Server-side';
31+
}
32+
33+
export function getFunctionInfo(data: FunctionData): any {
34+
return {
35+
description: data.shared?.description || data.client?.description || data.server?.description || '',
36+
type: getFunctionType(data),
37+
typePretty: getFunctionTypePretty(data),
38+
pair: data.shared?.pair || data.client?.pair || data.server?.pair || false,
39+
};
40+
}
2641

2742
const functionsCollection = await getCollection('functions');
2843
let functionsByCategory: FunctionsByCategory = {};

0 commit comments

Comments
 (0)