11import fs from 'fs' ;
22import path from 'path' ;
33
4+ interface MetaConfig {
5+ priority : number ;
6+ title : string ;
7+ }
8+
49// Priority configuration for directory and file sorting
5- const PRIORITY_CONFIG : Record < string , Record < string , number > > = {
10+ const PRIORITY_CONFIG : Record < string , Record < string , MetaConfig > > = {
611 'docs' : {
7- 'networks' : 100 ,
8- 'libs' : 90 ,
9- 'packages' : 80 ,
10- 'advanced' : 70 ,
12+ 'networks' : {
13+ priority : 100 ,
14+ title : 'Networks' ,
15+ } ,
16+ 'libs' : {
17+ priority : 90 ,
18+ title : 'Libraries' ,
19+ } ,
20+ 'packages' : {
21+ priority : 80 ,
22+ title : 'Packages' ,
23+ } ,
1124 } ,
1225 'libs' : {
13- 'cosmos-types' : 60 ,
14- 'interchainjs' : 50 ,
15- 'interchain-react' : 40 ,
26+ 'cosmos-types' : {
27+ priority : 60 ,
28+ title : 'Cosmos Types' ,
29+ } ,
30+ 'interchainjs' : {
31+ priority : 50 ,
32+ title : 'Interchain JS' ,
33+ } ,
34+ 'interchain-react' : {
35+ priority : 40 ,
36+ title : 'Interchain React' ,
37+ } ,
1638 } ,
1739 'networks' : {
18- 'cosmos' : 60 ,
19- 'ethereum' : 50 ,
20- 'injective' : 40 ,
40+ 'cosmos' : {
41+ priority : 60 ,
42+ title : 'Cosmos' ,
43+ } ,
44+ 'ethereum' : {
45+ priority : 50 ,
46+ title : 'Ethereum' ,
47+ } ,
48+ 'injective' : {
49+ priority : 40 ,
50+ title : 'Injective' ,
51+ } ,
2152 } ,
22- // Global defaults can be added here
23- '_global' : {
24- }
2553} ;
2654
2755// Base directory for docs
@@ -33,12 +61,7 @@ const DOCS_DIR = path.resolve(__dirname, '../../docs');
3361function getPriority ( context : string , key : string ) : number {
3462 // Check context-specific priority first
3563 if ( context && PRIORITY_CONFIG [ context ] && PRIORITY_CONFIG [ context ] [ key ] !== undefined ) {
36- return PRIORITY_CONFIG [ context ] [ key ] ;
37- }
38-
39- // Check global defaults
40- if ( PRIORITY_CONFIG [ '_global' ] && PRIORITY_CONFIG [ '_global' ] [ key ] !== undefined ) {
41- return PRIORITY_CONFIG [ '_global' ] [ key ] ;
64+ return PRIORITY_CONFIG [ context ] [ key ] . priority ;
4265 }
4366
4467 // Default priority for index is always 9999
@@ -50,6 +73,13 @@ function getPriority(context: string, key: string): number {
5073 return 0 ;
5174}
5275
76+ function getTitle ( context : string , key : string ) : string {
77+ if ( context && PRIORITY_CONFIG [ context ] && PRIORITY_CONFIG [ context ] [ key ] !== undefined ) {
78+ return PRIORITY_CONFIG [ context ] [ key ] . title ;
79+ }
80+ return formatTitle ( key ) ;
81+ }
82+
5383/**
5484 * Format a filename or directory name to a readable title
5585 */
@@ -83,22 +113,28 @@ function generateMetaContent(dirPath: string): Record<string, string> {
83113 : path . basename ( path . dirname ( dirPath ) ) ;
84114
85115 const entries = fs . readdirSync ( dirPath , { withFileTypes : true } ) ;
86- const meta : Record < string , string > = { } ;
116+ const meta : Record < string , MetaConfig > = { } ;
87117
88118 // Process files first (excluding _meta.json)
89119 entries
90120 . filter ( entry => entry . isFile ( ) && entry . name !== '_meta.json' && ! entry . name . startsWith ( '.' ) )
91121 . forEach ( entry => {
92122 // Extract name without extension
93123 const baseName = path . basename ( entry . name , path . extname ( entry . name ) ) ;
94- meta [ baseName ] = formatTitle ( baseName ) ;
124+ meta [ baseName ] = {
125+ title : getTitle ( context , baseName ) ,
126+ priority : getPriority ( context , baseName ) ,
127+ } ;
95128 } ) ;
96129
97130 // Then process directories
98131 entries
99132 . filter ( entry => entry . isDirectory ( ) && ! entry . name . startsWith ( '.' ) )
100133 . forEach ( entry => {
101- meta [ entry . name ] = formatTitle ( entry . name ) ;
134+ meta [ entry . name ] = {
135+ title : getTitle ( context , entry . name ) ,
136+ priority : getPriority ( context , entry . name ) ,
137+ } ;
102138 } ) ;
103139
104140 // Sort keys based on priority and then alphabetically
@@ -117,7 +153,7 @@ function generateMetaContent(dirPath: string): Record<string, string> {
117153 return a . localeCompare ( b ) ;
118154 } )
119155 . forEach ( key => {
120- sortedMeta [ key ] = meta [ key ] ;
156+ sortedMeta [ key ] = meta [ key ] . title ;
121157 } ) ;
122158
123159
0 commit comments