@@ -7,53 +7,72 @@ import {
77
88const client = createFigmaClient ( process . env . FIGMA_PERSONAL_ACCESS_TOKEN ! ) ;
99
10+ function getCategoryFromPath ( path : string ) : string | null {
11+ const match = path . match ( / c o m p o n e n t s \/ \( ( [ ^ ) ] + ) \) \/ / ) ;
12+ if ( ! match ) return null ;
13+
14+ return match [ 1 ] . charAt ( 0 ) . toUpperCase ( ) + match [ 1 ] . slice ( 1 ) ;
15+ }
16+
1017export async function ComponentGrid ( ) {
11- // Get all component pages
1218 const allPages = docsSource . getPages ( ) ;
1319
14- const componentPages = allPages
15- . filter ( ( page ) => {
16- // Only include pages under /docs/components/
17- if ( ! page . url . startsWith ( "/docs/components/" ) ) return false ;
20+ const categorizedPages = new Map < string , typeof allPages > ( ) ;
21+
22+ for ( const page of allPages ) {
23+ if ( ! page . url . startsWith ( "/docs/components/" ) ) continue ;
24+ if ( page . data . deprecated ) continue ;
1825
19- if ( page . data . deprecated ) return false ;
26+ const category = getCategoryFromPath ( page . path ) ;
2027
21- return true ;
22- } )
23- . sort ( ( a , b ) => {
24- // Sort alphabetically by title
25- const titleA = a . data . title ;
26- const titleB = b . data . title ;
28+ if ( ! category ) continue ;
2729
28- return titleA . localeCompare ( titleB ) ;
29- } ) ;
30+ if ( ! categorizedPages . has ( category ) ) {
31+ categorizedPages . set ( category , [ ] ) ;
32+ }
33+
34+ categorizedPages . get ( category ) ! . push ( page ) ;
35+ }
36+
37+ for ( const pages of categorizedPages . values ( ) ) {
38+ pages . sort ( ( a , b ) => a . data . title . localeCompare ( b . data . title ) ) ;
39+ }
40+
41+ const sortedCategories = Array . from ( categorizedPages . entries ( ) ) . sort ( ( [ a ] , [ b ] ) =>
42+ a . localeCompare ( b ) ,
43+ ) ;
3044
3145 return (
32- < ul className = "grid grid-cols-2 md:grid-cols-3 gap-4 pb-10 not-prose items-stretch" >
33- { componentPages . map ( async ( page ) => {
34- return (
35- < li key = { page . url } >
36- < ComponentCard
37- className = "h-full"
38- { ...( page . data . coverImageFigmaId && {
39- coverImageSrc : (
40- await fetchFigmaImageUrls ( {
41- client,
42- fileKey : process . env . FIGMA_FILE_KEY ! ,
43- nodeIds : [ page . data . coverImageFigmaId ] ,
44- options : {
45- scale : 3 ,
46- } ,
47- } )
48- ) . get ( page . data . coverImageFigmaId ) ,
49- } ) }
50- title = { page . data . title }
51- description = { page . data . description }
52- href = { page . url }
53- />
54- </ li >
55- ) ;
56- } ) }
57- </ ul >
46+ < div className = "space-y-10 pb-10" >
47+ { sortedCategories . map ( ( [ category , pages ] ) => (
48+ < section key = { category } >
49+ < h2 className = "text-xl font-semibold mb-4" > { category } </ h2 >
50+ < ul className = "grid grid-cols-2 md:grid-cols-3 gap-4 not-prose items-stretch" >
51+ { pages . map ( async ( page ) => (
52+ < li key = { page . url } >
53+ < ComponentCard
54+ className = "h-full"
55+ { ...( page . data . coverImageFigmaId && {
56+ coverImageSrc : (
57+ await fetchFigmaImageUrls ( {
58+ client,
59+ fileKey : process . env . FIGMA_FILE_KEY ! ,
60+ nodeIds : [ page . data . coverImageFigmaId ] ,
61+ options : {
62+ scale : 3 ,
63+ } ,
64+ } )
65+ ) . get ( page . data . coverImageFigmaId ) ,
66+ } ) }
67+ title = { page . data . title }
68+ description = { page . data . description }
69+ href = { page . url }
70+ />
71+ </ li >
72+ ) ) }
73+ </ ul >
74+ </ section >
75+ ) ) }
76+ </ div >
5877 ) ;
5978}
0 commit comments