Skip to content

Commit afa78ea

Browse files
committed
Merge branch 'docs/new-pages'
2 parents 73e897b + 108ff85 commit afa78ea

File tree

3 files changed

+59
-13
lines changed

3 files changed

+59
-13
lines changed

schemas/function.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ $defs:
163163
description: |
164164
The default value for this parameter, if none was given in the call to the function.
165165
This property automatically implicitly marks this parameter as optional.
166+
optional:
167+
type: boolean
168+
default: false
169+
description: If set to true, this parameter is optional.
166170

167171
returns:
168172
type: object

web/src/pages/[func].astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ if ( funcExamples.length > 0 ){
4646
tableOfContents: false,
4747
}}>
4848
{funcPair && (
49-
<p><strong>Pair:</strong> <a href={ funcPair }>{ funcPair }</a></p>
49+
<p><strong>Pair:</strong> <a href={ `/${funcPair}` }>{ funcPair }</a></p>
5050
)}
5151

5252
<!-- Description -->

web/src/utils/functions.ts

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,84 @@ import type { FunctionType } from './types';
55

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

8+
// Define a structure for function parameters
9+
type FunctionParameter = {
10+
name: string;
11+
type: string; // Adjust type as needed (e.g., string | string[])
12+
description?: string;
13+
optional?: boolean;
14+
};
15+
16+
// Define a structure for the details expected within shared/client/server
17+
type FunctionDetails = {
18+
description?: string;
19+
pair?: boolean;
20+
examples?: { code: string; description?: string }[];
21+
notes?: string[];
22+
parameters?: FunctionParameter[];
23+
};
24+
825
type FunctionsByCategory = {
926
[folder: string]: FunctionItem[];
1027
};
1128
type FunctionsByTypeByCategory = {
12-
shared: FunctionsByCategory;
13-
client: FunctionsByCategory;
14-
server: FunctionsByCategory;
29+
[key in FunctionType]: FunctionsByCategory;
1530
};
1631

32+
1733
export type FunctionData = {
1834
shared?: any;
1935
client?: any;
2036
server?: any;
2137
};
2238

39+
// Use the specific FunctionDetails type
40+
export type TypedFunctionData = {
41+
shared?: FunctionDetails;
42+
client?: FunctionDetails;
43+
server?: FunctionDetails;
44+
};
45+
2346
export const functionTypePrettyName = {
2447
'client': 'Client-side',
2548
'server': 'Server-side',
2649
'shared': 'Shared',
27-
};
50+
} as const; // Use 'as const' for stricter typing of keys
2851

2952
function getFunctionType(data: FunctionData): FunctionType {
3053
if (data.shared) return 'shared';
3154
if (data.client) return 'client';
3255
return 'server';
3356
}
3457
function getFunctionTypePretty(data: FunctionData): string {
58+
// No need for fallback, getFunctionType guarantees a valid FunctionType
3559
const funcType = getFunctionType(data);
36-
return functionTypePrettyName[funcType] ?? 'Server-side';
60+
return functionTypePrettyName[funcType];
3761
}
3862

39-
export function getFunctionInfo(data: FunctionData): any {
63+
// Define a return type for getFunctionInfo
64+
export type FunctionInfo = {
65+
description: string;
66+
type: FunctionType;
67+
typePretty: string;
68+
pair: boolean;
69+
examples: { code: string; description?: string }[];
70+
notes?: string[]; // Added notes
71+
parameters?: FunctionParameter[]; // Added parameters
72+
};
73+
74+
export function getFunctionInfo(data: TypedFunctionData): FunctionInfo {
75+
const type = getFunctionType(data);
76+
const details = data[type] ?? {}; // Get details based on type, default to empty object
77+
4078
return {
41-
description: data.shared?.description || data.client?.description || data.server?.description || '',
42-
type: getFunctionType(data),
79+
description: details.description || '',
80+
type: type,
4381
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 || [ ],
82+
pair: details.pair || false,
83+
examples: details.examples || [],
84+
notes: details.notes, // Extract notes (will be undefined if not present)
85+
parameters: details.parameters || [], // Extract parameters
4686
};
4787
}
4888

@@ -55,15 +95,17 @@ let functionsByTypeByCategory: FunctionsByTypeByCategory = {
5595
};
5696

5797
for (let func of functionsCollection) {
58-
const normalizedPath = path.normalize(func.filePath || '');
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
59100
const folder = path.basename(path.dirname(normalizedPath));
60101
if (!functionsByCategory[folder]) {
61102
functionsByCategory[folder] = [];
62103
}
63104
functionsByCategory[folder].push(func);
64105

65106
const funcType = getFunctionType(func.data);
66-
if (!functionsByTypeByCategory[funcType][folder]) {
107+
// Ensure the folder exists for the specific type
108+
if (!functionsByTypeByCategory[funcType]?.[folder]) {
67109
functionsByTypeByCategory[funcType][folder] = [];
68110
}
69111
functionsByTypeByCategory[funcType][folder].push(func);

0 commit comments

Comments
 (0)