1
1
import fs from 'fs' ;
2
2
import path from 'path' ;
3
3
4
+ interface MetaConfig {
5
+ priority : number ;
6
+ title : string ;
7
+ }
8
+
4
9
// 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 > > = {
6
11
'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
+ } ,
11
24
} ,
12
25
'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
+ } ,
16
38
} ,
17
39
'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
+ } ,
21
52
} ,
22
- // Global defaults can be added here
23
- '_global' : {
24
- }
25
53
} ;
26
54
27
55
// Base directory for docs
@@ -33,12 +61,7 @@ const DOCS_DIR = path.resolve(__dirname, '../../docs');
33
61
function getPriority ( context : string , key : string ) : number {
34
62
// Check context-specific priority first
35
63
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 ;
42
65
}
43
66
44
67
// Default priority for index is always 9999
@@ -50,6 +73,13 @@ function getPriority(context: string, key: string): number {
50
73
return 0 ;
51
74
}
52
75
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
+
53
83
/**
54
84
* Format a filename or directory name to a readable title
55
85
*/
@@ -83,22 +113,28 @@ function generateMetaContent(dirPath: string): Record<string, string> {
83
113
: path . basename ( path . dirname ( dirPath ) ) ;
84
114
85
115
const entries = fs . readdirSync ( dirPath , { withFileTypes : true } ) ;
86
- const meta : Record < string , string > = { } ;
116
+ const meta : Record < string , MetaConfig > = { } ;
87
117
88
118
// Process files first (excluding _meta.json)
89
119
entries
90
120
. filter ( entry => entry . isFile ( ) && entry . name !== '_meta.json' && ! entry . name . startsWith ( '.' ) )
91
121
. forEach ( entry => {
92
122
// Extract name without extension
93
123
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
+ } ;
95
128
} ) ;
96
129
97
130
// Then process directories
98
131
entries
99
132
. filter ( entry => entry . isDirectory ( ) && ! entry . name . startsWith ( '.' ) )
100
133
. 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
+ } ;
102
138
} ) ;
103
139
104
140
// Sort keys based on priority and then alphabetically
@@ -117,7 +153,7 @@ function generateMetaContent(dirPath: string): Record<string, string> {
117
153
return a . localeCompare ( b ) ;
118
154
} )
119
155
. forEach ( key => {
120
- sortedMeta [ key ] = meta [ key ] ;
156
+ sortedMeta [ key ] = meta [ key ] . title ;
121
157
} ) ;
122
158
123
159
0 commit comments