-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathgenerate-sidebar-config-fixed.js
More file actions
87 lines (71 loc) · 2.49 KB
/
generate-sidebar-config-fixed.js
File metadata and controls
87 lines (71 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env node
/**
* Generate proper sidebar configuration for 02-commands
* Accounts for base path in VitePress config
*/
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const DOCS_DIR = path.join(__dirname, 'docs', '02-commands')
const BASE_PATH = '/hana-developer-cli-tool-example'
function toTitleCase(str) {
return str.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ')
}
function getFileLabel(filename) {
return filename.replace('.md', '').split('-').map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(' ')
}
function generateSidebarConfig() {
const config = []
// Add reference links at top
config.push(` {
text: 'Commands Reference',
items: [
{ text: '📋 All Commands A-Z', link: '${BASE_PATH}/02-commands/all-commands' },
{ text: 'Commands Overview', link: '${BASE_PATH}/02-commands/' },
]
},`)
// Get all categories and sort them
const categories = fs.readdirSync(DOCS_DIR)
.filter(name => {
const fullPath = path.join(DOCS_DIR, name)
return fs.statSync(fullPath).isDirectory()
})
.sort()
// Generate config for each category
for (const category of categories) {
const categoryPath = path.join(DOCS_DIR, category)
const docFiles = fs.readdirSync(categoryPath)
.filter(f => f.endsWith('.md'))
.sort()
if (docFiles.length === 0) continue
const categoryTitle = toTitleCase(category)
const items = docFiles
.map(file => {
const link = `${BASE_PATH}/02-commands/${category}/${file.replace('.md', '')}`
const label = getFileLabel(file)
return ` { text: '${label}', link: '${link}' }`
})
.join(',\n')
config.push(` {
text: '${categoryTitle}',
items: [
${items}
]
},`)
}
return config.join('\n')
}
try {
const config = generateSidebarConfig()
const output = `'/02-commands/': [\n${config}\n ],`
console.log('Generated VitePress sidebar configuration with base path:')
console.log('=========================================\n')
console.log(output)
// Write to temp file for easy copying
fs.writeFileSync('vitepress-commands-config-fixed.txt', output)
console.log('\n\n✅ Configuration written to vitepress-commands-config-fixed.txt')
} catch (error) {
console.error('Error generating config:', error)
process.exit(1)
}