11// Build-time data loader: reads the community workflow examples under examples/
22// and exposes their metadata to the docs site gallery.
3- import { readFileSync } from "node:fs" ;
3+ import { existsSync , readFileSync } from "node:fs" ;
44import { basename , dirname } from "node:path" ;
55
66export interface ExampleMeta {
@@ -15,17 +15,12 @@ export interface ExampleMeta {
1515 event : string ;
1616 repoPath : string ; // e.g. examples/history-knowledge-qa
1717 hasPreview : boolean ;
18- previewUrl : string ;
18+ previewPath : string ;
1919}
2020
2121declare const data : ExampleMeta [ ] ;
2222export { data } ;
2323
24- const previewAssets = import . meta. glob ( "../../examples/*/preview.png" , {
25- eager : true ,
26- import : "default"
27- } ) as Record < string , string > ;
28-
2924function parseFrontmatter ( md : string ) : Record < string , string | string [ ] > | null {
3025 const m = md . match ( / ^ - - - \r ? \n ( [ \s \S ] * ?) \r ? \n - - - / ) ;
3126 if ( ! m ) return null ;
@@ -64,6 +59,8 @@ export default {
6459 if ( id === "TEMPLATE" ) continue ;
6560 const fm = parseFrontmatter ( readFileSync ( file , "utf8" ) ) ;
6661 if ( ! fm || ! fm . id ) continue ;
62+ const previewPath = `${ dirname ( file ) } /preview.png` ;
63+ const hasPreview = existsSync ( previewPath ) ;
6764 examples . push ( {
6865 id : String ( fm . id ) ,
6966 title : String ( fm . title ?? fm . id ) ,
@@ -75,8 +72,8 @@ export default {
7572 dslVersion : String ( fm . dslVersion ?? "" ) ,
7673 event : String ( fm . event ?? "" ) ,
7774 repoPath : `examples/${ id } ` ,
78- hasPreview : Boolean ( previewAssets [ `../../examples/ ${ id } /preview.png` ] ) ,
79- previewUrl : previewAssets [ `../../ examples/${ id } /preview.png`] ?? ""
75+ hasPreview,
76+ previewPath : hasPreview ? ` examples/${ id } /preview.png` : ""
8077 } ) ;
8178 }
8279 return examples . sort ( ( a , b ) => a . category . localeCompare ( b . category ) || a . title . localeCompare ( b . title ) ) ;
0 commit comments