Skip to content

Commit 1989e0f

Browse files
authored
Fix paths and important notes
1 parent f4469ef commit 1989e0f

File tree

8 files changed

+211
-41
lines changed

8 files changed

+211
-41
lines changed

functions/Element/setElementHealth.yaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ shared: &shared
88
description: |
99
This function sets the health of a [player](/player), [ped](/ped), [vehicle](/vehicle), or [object](/object) element.
1010
notes:
11-
- |
12-
In the case of the [vehicle](/vehicle) element, the health ranges from 0 to 1000.
13-
14-
- *1000:* no damage at all
15-
- *650:* white steam 0%, black smoke 0%
16-
- *450:* white steam 100%, black smoke 50%
17-
- *250:* white steam 0%, black smoke 100%
18-
- *249:* fire with big black smoke (blowing up)
11+
- type: 'standard'
12+
content: |
13+
In the case of the [vehicle](/vehicle) element, the health ranges from 0 to 1000.
14+
15+
- *1000:* no damage at all
16+
- *650:* white steam 0%, black smoke 0%
17+
- *450:* white steam 100%, black smoke 50%
18+
- *250:* white steam 0%, black smoke 100%
19+
- *249:* fire with big black smoke (blowing up)
1920
parameters:
2021
- name: 'theElement'
2122
type: 'element'

schemas/common-defs.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,25 @@ type: object
55
$defs:
66
notes:
77
type: array
8-
description: List of noteworthy pieces of information for the item.
8+
description: |
9+
List of noteworthy pieces of information for the item.
10+
Each note can be of a specific type, e.g., 'standard' or 'important'.
911
items:
10-
type: string
12+
type: object
13+
description: An individual note item.
14+
required:
15+
- content
16+
properties:
17+
type:
18+
type: string
19+
description: The type of the note, influencing its presentation.
20+
enum:
21+
- standard
22+
- important
23+
default: standard
24+
content:
25+
type: string
26+
description: The textual content of the note. Can use markdown and YAML multi-line strings.
1127

1228
meta:
1329
type: array

schemas/function.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,4 @@ $defs:
150150
description: Type of the return value.
151151
name:
152152
type: string
153-
description: Name of the return value.
153+
description: Name of the return value.

web/src/components/NoteBox.astro

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
import type { HTMLAttributes } from 'astro/types';
3+
4+
interface Props extends HTMLAttributes<'div'> {
5+
type?: 'standard' | 'important';
6+
}
7+
8+
const { type = 'standard', class: className, ...rest } = Astro.props;
9+
---
10+
<div
11+
class:list={["custom-note-box", { 'note-important': type === 'important' }, className]}
12+
{...rest}
13+
>
14+
{type === 'important' && (
15+
<span class="note-icon" aria-label="Importante">
16+
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" aria-hidden="true">
17+
<circle cx="10" cy="10" r="10" fill="#e53935"/>
18+
<text x="10" y="15" text-anchor="middle" font-size="14" fill="#fff" font-family="Arial" font-weight="bold">!</text>
19+
</svg>
20+
</span>
21+
)}
22+
<slot />
23+
</div >
24+
25+
<style>
26+
.custom-note-box {
27+
background-color: var(--sl-color-blue-low);
28+
border-left: 4px solid var(--sl-color-blue);
29+
border-radius: 8px;
30+
padding: 1rem 1.25rem;
31+
margin-bottom: 1rem;
32+
color: var(--sl-color-text);
33+
position: relative;
34+
}
35+
36+
html[data-theme="dark"] .custom-note-box {
37+
background-color: var(--sl-color-gray-5);
38+
}
39+
40+
.custom-note-box.note-important {
41+
background-color: var(--sl-color-red-low);
42+
border-left-color: #d32f2f;
43+
}
44+
45+
html[data-theme="dark"] .custom-note-box.note-important {
46+
--sl-color-red-low: hsl(var(--sl-color-red-hue), 50%, 20%);
47+
}
48+
49+
.note-icon {
50+
position: absolute;
51+
top: 0.75rem;
52+
right: 0.75rem;
53+
z-index: 1;
54+
display: flex;
55+
align-items: center;
56+
justify-content: center;
57+
pointer-events: none;
58+
}
59+
.custom-note-box.note-important {
60+
padding-right: 2.5rem;
61+
padding-left: 1.25rem;
62+
}
63+
</style>

web/src/pages/[func].astro

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import fs from "fs";
77
import path from "path";
88
import { Code } from '@astrojs/starlight/components';
99
10+
import NoteBox from '@src/components/NoteBox.astro';
11+
import '@src/styles/function-page.css';
12+
import type { NotesType } from '@src/utils/types';
13+
1014
export async function getStaticPaths() {
1115
const functions = await getCollection('functions');
1216
return functions.map(func => ({
@@ -19,24 +23,30 @@ const { func } = Astro.props;
1923
2024
const funcInfo = getFunctionInfo(func.data);
2125
const funcType = funcInfo.type;
22-
const funcTypePretty = funcInfo.typePretty;
23-
2426
const funcPair = funcInfo.pair;
25-
const funcPath = path.dirname(func.filePath ?? "")
26-
let funcExamples = funcInfo.examples
27+
const funcPath = path.dirname(func.filePath ?? "");
2728
28-
if ( funcExamples.length > 0 ){
29-
funcExamples = funcInfo.examples.map((example: any) => {
29+
const { description, notes: funcNotes, examples: rawExamples } = funcInfo;
30+
31+
let processedExamples: any[] = [];
32+
if (Array.isArray(rawExamples) && rawExamples.length > 0) {
33+
processedExamples = rawExamples.map((example: any) => {
3034
try {
31-
const luaCode = fs.readFileSync(path.resolve(`${funcPath}`, example.path), "utf8");
35+
const exampleFilePath = path.resolve(funcPath, example.path);
36+
const luaCode = fs.readFileSync(exampleFilePath, "utf8");
3237
return { ...example, luaCode };
3338
} catch (error) {
34-
console.error(`Error reading ${example.path}:`, error);
35-
return { ...example, luaCode: "Loading example error." };
39+
console.error(`Error reading example file ${example.path} at ${path.resolve(funcPath, example.path)}:`, error);
40+
return { ...example, luaCode: `Error loading example: ${example.path}` };
3641
}
3742
});
3843
}
3944
45+
let notesContent: NotesType = [];
46+
if (Array.isArray(funcNotes) && funcNotes.length > 0) {
47+
notesContent = funcNotes;
48+
}
49+
4050
---
4151

4252
<div class={"show-type-badge-" + funcType}>
@@ -45,18 +55,34 @@ if ( funcExamples.length > 0 ){
4555
title: func.id,
4656
tableOfContents: false,
4757
}}>
58+
<!-- Pair Function Ref -->
4859
{funcPair && (
49-
<p><strong>Pair:</strong> <a href={ funcPair }>{ funcPair }</a></p>
60+
<p><strong>Pair:</strong> <a href={ `/${funcPair}` }>{ funcPair }</a></p>
5061
)}
5162

5263
<!-- Description -->
53-
<Fragment set:html={marked(funcInfo.description)} />
64+
{description && <Fragment set:html={marked(description)} />}
65+
66+
<!-- Notes -->
67+
<div class="notes-section">
68+
{notesContent.map((note) => (
69+
<NoteBox type={note.type}>
70+
<Fragment set:html={marked(note.content)} />
71+
</NoteBox>
72+
))}
73+
</div>
5474

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)} />
75+
<!-- Examples -->
76+
{processedExamples.length > 0 && (
77+
<div class="examples-section">
78+
<h3>Exemplos</h3>
79+
{processedExamples.map((example: any) => (
80+
<div class="function-example">
81+
<Fragment set:html={marked(example.description)} />
82+
<Code code={example.luaCode} lang="lua" title={path.basename(example.path)} />
83+
</div>
84+
))}
5985
</div>
60-
))}
86+
)}
6187
</StarlightPage>
6288
</div>

web/src/styles/function-page.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.function-syntax,
2+
.function-oop,
3+
.notes-section,
4+
.examples-section {
5+
margin-top: 1.5rem;
6+
margin-bottom: 1.5rem;
7+
}
8+
9+
.function-syntax h3,
10+
.function-oop h3,
11+
.examples-section h3 {
12+
margin-bottom: 0.75rem;
13+
font-size: 1.25em;
14+
border-bottom: 1px solid var(--sl-color-gray-5);
15+
padding-bottom: 0.25rem;
16+
}
17+
18+
.function-example {
19+
margin-bottom: 1.5rem;
20+
}
21+
.function-example > :first-child {
22+
margin-bottom: 0.5rem;
23+
}
24+
.examples-section .function-example:last-child {
25+
margin-bottom: 0;
26+
}

web/src/utils/functions.ts

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,49 @@
11
import { getCollection } from 'astro:content';
22
import path from 'path';
33

4-
import type { FunctionType } from './types';
4+
import type { FunctionType, NotesType } from './types';
55

66
type FunctionItem = Awaited<ReturnType<typeof getCollection>>[number];
77

8+
type FunctionParameter = {
9+
name: string;
10+
type: string;
11+
description?: string;
12+
};
13+
14+
type FunctionDetails = {
15+
description?: string;
16+
pair?: boolean;
17+
examples?: { code: string; description?: string }[];
18+
notes?: NotesType;
19+
parameters?: FunctionParameter[];
20+
};
21+
822
type FunctionsByCategory = {
923
[folder: string]: FunctionItem[];
1024
};
1125
type FunctionsByTypeByCategory = {
12-
shared: FunctionsByCategory;
13-
client: FunctionsByCategory;
14-
server: FunctionsByCategory;
26+
[key in FunctionType]: FunctionsByCategory;
1527
};
1628

29+
1730
export type FunctionData = {
1831
shared?: any;
1932
client?: any;
2033
server?: any;
2134
};
2235

36+
export type TypedFunctionData = {
37+
shared?: FunctionDetails;
38+
client?: FunctionDetails;
39+
server?: FunctionDetails;
40+
};
41+
2342
export const functionTypePrettyName = {
2443
'client': 'Client-side',
2544
'server': 'Server-side',
2645
'shared': 'Shared',
27-
};
46+
} as const;
2847

2948
function getFunctionType(data: FunctionData): FunctionType {
3049
if (data.shared) return 'shared';
@@ -33,16 +52,31 @@ function getFunctionType(data: FunctionData): FunctionType {
3352
}
3453
function getFunctionTypePretty(data: FunctionData): string {
3554
const funcType = getFunctionType(data);
36-
return functionTypePrettyName[funcType] ?? 'Server-side';
55+
return functionTypePrettyName[funcType];
3756
}
3857

39-
export function getFunctionInfo(data: FunctionData): any {
58+
export type FunctionInfo = {
59+
description: string;
60+
type: FunctionType;
61+
typePretty: string;
62+
pair: boolean;
63+
examples: { code: string; description?: string }[];
64+
notes?: NotesType;
65+
parameters?: FunctionParameter[];
66+
};
67+
68+
export function getFunctionInfo(data: TypedFunctionData): FunctionInfo {
69+
const type = getFunctionType(data);
70+
const details = data[type] ?? {};
71+
4072
return {
41-
description: data.shared?.description || data.client?.description || data.server?.description || '',
42-
type: getFunctionType(data),
73+
description: details.description || '',
74+
type: type,
4375
typePretty: getFunctionTypePretty(data),
44-
pair: data.shared?.pair || data.client?.pair || data.server?.pair || false,
45-
examples: data.shared?.examples || data.client?.examples || data.server?.examples || [ ],
76+
pair: details.pair || false,
77+
examples: details.examples || [],
78+
notes: details.notes || [],
79+
parameters: details.parameters || [],
4680
};
4781
}
4882

@@ -55,15 +89,15 @@ let functionsByTypeByCategory: FunctionsByTypeByCategory = {
5589
};
5690

5791
for (let func of functionsCollection) {
58-
const normalizedPath = path.normalize(func.filePath || '');
92+
const normalizedPath = path.normalize(func.id);
5993
const folder = path.basename(path.dirname(normalizedPath));
6094
if (!functionsByCategory[folder]) {
6195
functionsByCategory[folder] = [];
6296
}
6397
functionsByCategory[folder].push(func);
6498

6599
const funcType = getFunctionType(func.data);
66-
if (!functionsByTypeByCategory[funcType][folder]) {
100+
if (!functionsByTypeByCategory[funcType]?.[folder]) {
67101
functionsByTypeByCategory[funcType][folder] = [];
68102
}
69103
functionsByTypeByCategory[funcType][folder].push(func);

web/src/utils/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
export type FunctionType = 'shared' | 'client' | 'server';
1+
export type FunctionType = 'shared' | 'client' | 'server';
2+
export type NotesType = {
3+
type: 'standard' | 'important';
4+
content: string;
5+
}[];

0 commit comments

Comments
 (0)