Skip to content

Commit 5c00129

Browse files
committed
add title mapping to meta.json
1 parent c799551 commit 5c00129

File tree

3 files changed

+62
-26
lines changed

3 files changed

+62
-26
lines changed

docs/_meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"index": "Overview",
33
"networks": "Networks",
4-
"libs": "Libs",
4+
"libs": "Libraries",
55
"packages": "Packages",
66
"advanced": "Advanced"
77
}

docs/libs/_meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"cosmos-types": "Cosmos Types",
3-
"interchainjs": "Interchainjs",
3+
"interchainjs": "Interchain JS",
44
"interchain-react": "Interchain React"
55
}

scripts/docs/generate_meta_json.ts

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,55 @@
11
import fs from 'fs';
22
import 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');
3361
function 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

Comments
 (0)