Skip to content

Commit d1961fa

Browse files
committed
Update generate_module_docs.js
1 parent 4412dbb commit d1961fa

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

generate_module_docs.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,32 @@ function toFolderName(name) {
2626
.replace(/^_+|_+$/g, '')
2727
}
2828

29+
function toSlug(name) {
30+
return String(name)
31+
.toLowerCase()
32+
.replace(/[^a-z0-9]+/g, '-')
33+
.replace(/^-+|-$/g, '')
34+
}
35+
36+
function parseREADME(filePath) {
37+
try {
38+
const content = fs.readFileSync(filePath, 'utf8')
39+
40+
// Extract name
41+
const nameMatch = content.match(/\*\*Name:\*\*\s*(.+)/)
42+
const name = nameMatch ? nameMatch[1].trim() : ''
43+
44+
// Extract description (everything between "Description:" and the next heading or end)
45+
const descMatch = content.match(/\*\*Description:\*\*\s*\n\n(.+?)(?:\n\n<h2|<h3|\n<p align|$)/s)
46+
const description = descMatch ? descMatch[1].trim() : ''
47+
48+
return { name, description }
49+
} catch (error) {
50+
return { name: '', description: '' }
51+
}
52+
}
53+
54+
// First, copy README.md files as about.md
2955
for (const mod of modules) {
3056
const id = mod.versionID || ''
3157
if (!id) continue
@@ -42,3 +68,48 @@ for (const mod of modules) {
4268
}
4369

4470
console.log('README.md files copied as about.md.')
71+
72+
// Generate modules.md
73+
const outputPath = path.join(__dirname, 'documentation', 'modules.md')
74+
const outputDir = path.dirname(outputPath)
75+
76+
// Ensure documentation directory exists
77+
fs.mkdirSync(outputDir, { recursive: true })
78+
79+
let moduleList = []
80+
81+
// Get all directories in the current folder
82+
const entries = fs.readdirSync(__dirname, { withFileTypes: true })
83+
84+
for (const entry of entries) {
85+
if (!entry.isDirectory()) continue
86+
if (entry.name === '.github' || entry.name === 'node_modules' || entry.name === 'documentation') continue
87+
88+
const moduleDir = path.join(__dirname, entry.name)
89+
const readmePath = path.join(moduleDir, 'README.md')
90+
91+
if (!fs.existsSync(readmePath)) continue
92+
93+
const { name, description } = parseREADME(readmePath)
94+
if (!name) continue
95+
96+
moduleList.push({ name, description, folder: entry.name })
97+
}
98+
99+
// Sort modules alphabetically
100+
moduleList.sort((a, b) => a.name.localeCompare(b.name))
101+
102+
// Generate markdown content
103+
let markdown = '# List of Modules\n\n'
104+
105+
for (const module of moduleList) {
106+
const slug = toSlug(module.name)
107+
const url = `https://bleonheart.github.io/modules/${slug}/`
108+
109+
markdown += `## [${module.name}](${url})\n`
110+
markdown += `${module.description}\n\n`
111+
}
112+
113+
fs.writeFileSync(outputPath, markdown)
114+
115+
console.log(`Generated modules.md with ${moduleList.length} modules at ${outputPath}`)

0 commit comments

Comments
 (0)