Skip to content

Commit a592e97

Browse files
committed
Merge branch 'docs/new-features'
2 parents afa78ea + bdb90cd commit a592e97

File tree

5 files changed

+104
-28
lines changed

5 files changed

+104
-28
lines changed

schemas/function.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ $defs:
4343
description:
4444
type: string
4545
description: Describes the functionality provided by the function.
46+
important_notes:
47+
type: array
48+
description: |
49+
A list of important notes about the function.
50+
This is a list of things that are important to know about the function, but not
51+
necessarily related to the function itself.
52+
items:
53+
type: string
4654
notes:
4755
type: array
4856
description: List of noteworthy pieces of information for the function.

web/src/components/NoteBox.astro

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
---
3+
<div class="custom-note-box">
4+
<slot />
5+
</div >
6+
7+
<style>
8+
.custom-note-box {
9+
background-color: var(--sl-color-blue-low);
10+
border-left: 4px solid var(--sl-color-blue);
11+
border-radius: 8px;
12+
padding: 1rem 1.25rem;
13+
margin-bottom: 1rem;
14+
color: var(--sl-color-text);
15+
}
16+
html[data-theme="dark"] .custom-note-box {
17+
background-color: var(--sl-color-gray-5);
18+
}
19+
</style>

web/src/pages/[func].astro

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ 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+
1013
export async function getStaticPaths() {
1114
const functions = await getCollection('functions');
1215
return functions.map(func => ({
@@ -19,24 +22,30 @@ const { func } = Astro.props;
1922
2023
const funcInfo = getFunctionInfo(func.data);
2124
const funcType = funcInfo.type;
22-
const funcTypePretty = funcInfo.typePretty;
23-
2425
const funcPair = funcInfo.pair;
25-
const funcPath = path.dirname(func.filePath ?? "")
26-
let funcExamples = funcInfo.examples
26+
const funcPath = path.dirname(func.filePath ?? "");
2727
28-
if ( funcExamples.length > 0 ){
29-
funcExamples = funcInfo.examples.map((example: any) => {
28+
const { description, notes: funcNotes, examples: rawExamples } = funcInfo;
29+
30+
let processedExamples: any[] = [];
31+
if (Array.isArray(rawExamples) && rawExamples.length > 0) {
32+
processedExamples = rawExamples.map((example: any) => {
3033
try {
31-
const luaCode = fs.readFileSync(path.resolve(`${funcPath}`, example.path), "utf8");
34+
const exampleFilePath = path.resolve(funcPath, example.path);
35+
const luaCode = fs.readFileSync(exampleFilePath, "utf8");
3236
return { ...example, luaCode };
3337
} catch (error) {
34-
console.error(`Error reading ${example.path}:`, error);
35-
return { ...example, luaCode: "Loading example error." };
38+
console.error(`Error reading example file ${example.path} at ${path.resolve(funcPath, example.path)}:`, error);
39+
return { ...example, luaCode: `Error loading example: ${example.path}` };
3640
}
3741
});
3842
}
3943
44+
let notesContent: string[] = [];
45+
if (Array.isArray(funcNotes) && funcNotes.length > 0) {
46+
notesContent = funcNotes;
47+
}
48+
4049
---
4150

4251
<div class={"show-type-badge-" + funcType}>
@@ -45,18 +54,34 @@ if ( funcExamples.length > 0 ){
4554
title: func.id,
4655
tableOfContents: false,
4756
}}>
57+
<!-- Pair Function Ref -->
4858
{funcPair && (
4959
<p><strong>Pair:</strong> <a href={ `/${funcPair}` }>{ funcPair }</a></p>
5060
)}
5161

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

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)} />
74+
<!-- Examples -->
75+
{processedExamples.length > 0 && (
76+
<div class="examples-section">
77+
<h3>Exemplos</h3>
78+
{processedExamples.map((example: any) => (
79+
<div class="function-example">
80+
<Fragment set:html={marked(example.description)} />
81+
<Code code={example.luaCode} lang="lua" title={path.basename(example.path)} />
82+
</div>
83+
))}
5984
</div>
60-
))}
85+
)}
6186
</StarlightPage>
6287
</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: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type FunctionItem = Awaited<ReturnType<typeof getCollection>>[number];
88
// Define a structure for function parameters
99
type FunctionParameter = {
1010
name: string;
11-
type: string; // Adjust type as needed (e.g., string | string[])
11+
type: string;
1212
description?: string;
1313
optional?: boolean;
1414
};
@@ -19,6 +19,7 @@ type FunctionDetails = {
1919
pair?: boolean;
2020
examples?: { code: string; description?: string }[];
2121
notes?: string[];
22+
important_notes?: string[];
2223
parameters?: FunctionParameter[];
2324
};
2425

@@ -36,7 +37,6 @@ export type FunctionData = {
3637
server?: any;
3738
};
3839

39-
// Use the specific FunctionDetails type
4040
export type TypedFunctionData = {
4141
shared?: FunctionDetails;
4242
client?: FunctionDetails;
@@ -47,42 +47,42 @@ export const functionTypePrettyName = {
4747
'client': 'Client-side',
4848
'server': 'Server-side',
4949
'shared': 'Shared',
50-
} as const; // Use 'as const' for stricter typing of keys
50+
} as const;
5151

5252
function getFunctionType(data: FunctionData): FunctionType {
5353
if (data.shared) return 'shared';
5454
if (data.client) return 'client';
5555
return 'server';
5656
}
5757
function getFunctionTypePretty(data: FunctionData): string {
58-
// No need for fallback, getFunctionType guarantees a valid FunctionType
5958
const funcType = getFunctionType(data);
6059
return functionTypePrettyName[funcType];
6160
}
6261

63-
// Define a return type for getFunctionInfo
6462
export type FunctionInfo = {
6563
description: string;
6664
type: FunctionType;
6765
typePretty: string;
6866
pair: boolean;
6967
examples: { code: string; description?: string }[];
70-
notes?: string[]; // Added notes
71-
parameters?: FunctionParameter[]; // Added parameters
68+
notes?: string[];
69+
important_notes?: string[];
70+
parameters?: FunctionParameter[];
7271
};
7372

7473
export function getFunctionInfo(data: TypedFunctionData): FunctionInfo {
7574
const type = getFunctionType(data);
76-
const details = data[type] ?? {}; // Get details based on type, default to empty object
75+
const details = data[type] ?? {};
7776

7877
return {
7978
description: details.description || '',
8079
type: type,
8180
typePretty: getFunctionTypePretty(data),
8281
pair: details.pair || false,
8382
examples: details.examples || [],
84-
notes: details.notes, // Extract notes (will be undefined if not present)
85-
parameters: details.parameters || [], // Extract parameters
83+
notes: details.notes || [],
84+
important_notes: details.important_notes || [],
85+
parameters: details.parameters || [],
8686
};
8787
}
8888

@@ -95,16 +95,14 @@ let functionsByTypeByCategory: FunctionsByTypeByCategory = {
9595
};
9696

9797
for (let func of functionsCollection) {
98-
// Assuming func.filePath exists, handle potential undefined if necessary
99-
const normalizedPath = path.normalize(func.id); // Use func.id which includes the path relative to content dir
98+
const normalizedPath = path.normalize(func.id);
10099
const folder = path.basename(path.dirname(normalizedPath));
101100
if (!functionsByCategory[folder]) {
102101
functionsByCategory[folder] = [];
103102
}
104103
functionsByCategory[folder].push(func);
105104

106105
const funcType = getFunctionType(func.data);
107-
// Ensure the folder exists for the specific type
108106
if (!functionsByTypeByCategory[funcType]?.[folder]) {
109107
functionsByTypeByCategory[funcType][folder] = [];
110108
}

0 commit comments

Comments
 (0)