@@ -3,6 +3,9 @@ import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
33import { getCollection } from ' astro:content' ;
44import { getFunctionInfo } from ' @src/utils/functions' ;
55import { marked } from ' marked' ;
6+ import fs from " fs" ;
7+ import path from " path" ;
8+ import { Code } from ' @astrojs/starlight/components' ;
69
710export async function getStaticPaths() {
811 const functions = await getCollection (' functions' );
@@ -15,11 +18,24 @@ export async function getStaticPaths() {
1518const { func } = Astro .props ;
1619
1720const funcInfo = getFunctionInfo (func .data );
18-
1921const funcType = funcInfo .type ;
2022const funcTypePretty = funcInfo .typePretty ;
2123
2224const funcPair = funcInfo .pair ;
25+ const funcPath = path .dirname (func .filePath ?? " " )
26+ let funcExamples = funcInfo .examples
27+
28+ if ( funcExamples .length > 0 ){
29+ funcExamples = funcInfo .examples .map ((example : any ) => {
30+ try {
31+ const luaCode = fs .readFileSync (path .resolve (` ${funcPath } ` , example .path ), " utf8" );
32+ return { ... example , luaCode };
33+ } catch (error ) {
34+ console .error (` Error reading ${example .path }: ` , error );
35+ return { ... example , luaCode: " Loading example error." };
36+ }
37+ });
38+ }
2339---
2440
2541<StarlightPage frontmatter ={ {
@@ -35,4 +51,12 @@ const funcPair = funcInfo.pair;
3551
3652 <!-- Description -->
3753 <Fragment set:html ={ marked (funcInfo .description )} />
54+
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 )} />
59+ </div >
60+ ))}
61+
3862</StarlightPage >
0 commit comments