11import type { ComponentAPI } from '$lib/api-types.js' ;
22import { allComponents , allUtils , allGuides } from 'content-collections' ;
33import { sortCollection } from '$lib/collections.js' ;
4- // Use import.meta.glob to load files at build time (Cloudflare Workers compatible)
4+
55const exampleSources = import . meta. glob < string > ( '/src/examples/**/*.svelte' , {
66 eager : true ,
77 query : '?raw' ,
@@ -428,14 +428,6 @@ export function getSortedGuides(): GuideEntry[] {
428428 ] ;
429429}
430430
431- /**
432- * Generate the "General" section listing all guides as links.
433- */
434- export function generateGuidesSection ( ) : string {
435- const guides = getSortedGuides ( ) ;
436- return `## General\n\n${ guides . map ( ( g ) => `- [${ g . name } ](${ docsUrl ( 'guides' , g . slug ) } ): ${ g . description } ` ) . join ( '\n' ) } ` ;
437- }
438-
439431export interface GenerateGuideMarkdownOptions {
440432 /** The name/slug of the guide (e.g., 'getting-started', 'styles') */
441433 name : string ;
@@ -519,7 +511,7 @@ export function getAllExamplePaths(): string[] {
519511export interface CollectionListOptions {
520512 title : string ;
521513 items : Array < { slug : string ; name : string ; description ?: string } > ;
522- type : 'components' | 'utils' ;
514+ type : 'components' | 'utils' | 'guides' ;
523515}
524516
525517/**
@@ -528,13 +520,14 @@ export interface CollectionListOptions {
528520export function generateCollectionListSection ( options : CollectionListOptions ) : string {
529521 const { title, items, type } = options ;
530522
523+ const fallbackLabel =
524+ type === 'components' ? 'component' : type === 'utils' ? 'utility' : 'guide' ;
525+
531526 const lines = items
532527 . filter ( ( item ) => item . slug && item . name )
533528 . sort ( ( a , b ) => a . name . localeCompare ( b . name ) )
534529 . map ( ( item ) => {
535- const description =
536- item . description ||
537- `Documentation for ${ item . name } ${ type === 'components' ? 'component' : 'utility' } ` ;
530+ const description = item . description || `Documentation for ${ item . name } ${ fallbackLabel } ` ;
538531 return `- [${ item . name } ](${ llmsUrl ( type , item . slug ) } ): ${ description } ` ;
539532 } ) ;
540533
@@ -553,8 +546,11 @@ export function generateExampleMarkdown(componentSlug: string, exampleName: stri
553546
554547 // Find components used in this example from the catalog
555548 const catalog = getCatalog ( componentSlug ) ;
556- const exampleInfo = ( catalog ?. examples as Array < { name : string ; components : Array < { component : string } > } > | undefined )
557- ?. find ( ( e ) => e . name === exampleName ) ;
549+ const exampleInfo = (
550+ catalog ?. examples as
551+ | Array < { name : string ; components : Array < { component : string } > } >
552+ | undefined
553+ ) ?. find ( ( e ) => e . name === exampleName ) ;
558554 const usedComponentNames = [ ...new Set ( exampleInfo ?. components . map ( ( c ) => c . component ) ?? [ ] ) ] ;
559555 const usedComponents = usedComponentNames
560556 . map ( ( c ) => allComponents . find ( ( ac ) => ac . name === c ) )
@@ -595,19 +591,26 @@ export function generateLlmsTxt(): string {
595591
596592This file contains links to LLM-optimized documentation in markdown format.` ) ;
597593
598- sections . push ( generateGuidesSection ( ) ) ;
594+ // Guides
595+ sections . push (
596+ generateCollectionListSection ( { title : 'Guides' , items : getSortedGuides ( ) , type : 'guides' } )
597+ ) ;
598+
599+ // Components
599600 sections . push (
600601 generateCollectionListSection ( {
601602 title : 'Components' ,
602603 items : allComponents ,
603604 type : 'components'
604605 } )
605606 ) ;
607+
608+ // Utilities
606609 sections . push (
607610 generateCollectionListSection ( { title : 'Utilities' , items : allUtils , type : 'utils' } )
608611 ) ;
609612
610- // Examples section
613+ // Examples
611614 const paths = getAllExamplePaths ( ) ;
612615 const examples : string [ ] = [ ] ;
613616 for ( const path of paths ) {
@@ -639,7 +642,9 @@ export function generateFullLlmsTxt(): string {
639642
640643This file contains the complete LLM-optimized documentation for all components and utilities.` ) ;
641644
642- sections . push ( generateGuidesSection ( ) ) ;
645+ sections . push (
646+ generateCollectionListSection ( { title : 'Guides' , items : getSortedGuides ( ) , type : 'guides' } )
647+ ) ;
643648
644649 // Components section - full content
645650 sections . push ( '---\n\n# Components' ) ;
0 commit comments