Skip to content

Commit 37523c8

Browse files
committed
Update generate_module_docs.js
1 parent d91a9e3 commit 37523c8

1 file changed

Lines changed: 27 additions & 11 deletions

File tree

generate_module_docs.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,23 @@ function parseChangelog(content) {
3737
while ((match = keyRegex.exec(content)) !== null) {
3838
versions.push({
3939
version: match[1],
40-
startIndex: match.index + match[0].length
40+
valueStart: match.index + match[0].length,
41+
matchStart: match.index
4142
})
4243
}
4344

4445
for (let i = 0; i < versions.length; i++) {
4546
const v = versions[i]
46-
const nextStart = versions[i + 1] ? versions[i + 1].startIndex - versions[i + 1].version.length - 10 : content.length
47-
const rawValue = content.substring(v.startIndex, nextStart).trim()
47+
// The value ends either at the start of the next key or the end of the string
48+
const valueEnd = versions[i + 1] ? versions[i + 1].matchStart : content.length
49+
let rawValue = content.substring(v.valueStart, valueEnd).trim()
50+
51+
// Remove trailing comma if it exists (common in Lua tables)
52+
if (rawValue.endsWith(',')) {
53+
rawValue = rawValue.substring(0, rawValue.length - 1).trim()
54+
}
4855

4956
if (rawValue.startsWith('{')) {
50-
// It's a table, extract everything between the outer braces
5157
let braceCount = 0
5258
let tableContent = ""
5359
for (let j = 0; j < rawValue.length; j++) {
@@ -60,8 +66,7 @@ function parseChangelog(content) {
6066
}
6167
changelog[v.version] = parseLuaTable(tableContent)
6268
} else {
63-
// It's a string, extract everything between the first and last quote
64-
const stringMatch = rawValue.match(/"([^"]*)"/)
69+
const stringMatch = rawValue.match(/["']([^"']*)["']/)
6570
if (stringMatch) {
6671
changelog[v.version] = [stringMatch[1]]
6772
}
@@ -173,40 +178,51 @@ function main() {
173178
const changelogData = mod.changelogData || {}
174179
const slug = toSlug(name)
175180

181+
// Main module block starts here
176182
markdown += `<details class="realm-shared" id="module-${slug}">\n`
177183
markdown += `<summary><a id="${name}"></a>${name}</summary>\n`
178184
markdown += `<div class="details-content">\n`
179185
markdown += `<a id="${slug}"></a>\n`
180186

187+
// 1. Description Section
181188
markdown += `<strong>Description</strong>\n`
182189
markdown += `<p>${description.trim()}</p>\n\n`
183190

191+
// 2. Changelog Section
184192
const versions = Object.keys(changelogData).sort((a, b) => b.localeCompare(a, undefined, { numeric: true, sensitivity: 'base' }))
185193
if (versions.length > 0) {
186194
markdown += `<strong>Changelog</strong>\n`
187195

196+
// Each version is its own collapsible window
188197
versions.forEach(version => {
189-
markdown += `<details class="realm-shared" id="changelog-${slug}-${toSlug(version)}">\n`
198+
const vSlug = toSlug(version) || 'v'
199+
markdown += `<details class="realm-shared" id="changelog-${slug}-${vSlug}">\n`
190200
markdown += `<summary>Version ${version}</summary>\n`
191201
markdown += `<div class="details-content">\n`
192202
markdown += `<ul>\n`
193-
changelogData[version].forEach(entry => {
194-
markdown += ` <li>${entry.trim()}</li>\n`
203+
204+
const entries = changelogData[version] || []
205+
entries.forEach(entry => {
206+
markdown += ` <li>${String(entry).trim()}</li>\n`
195207
})
208+
196209
markdown += `</ul>\n`
197210
markdown += `</div>\n`
198211
markdown += `</details>\n`
199212
})
200213
markdown += `\n`
201214
}
202215

216+
// 3. Download Section
203217
markdown += `<div style="display: flex; justify-content: center; margin-top: 20px;">\n`
204218
markdown += ` <a href="${download}" style="display: inline-block; padding: 12px 24px; background-color: #007bff; color: white; text-decoration: none; border-radius: 6px; font-weight: bold; transition: background-color 0.2s;">\n`
205219
markdown += ` Download\n`
206220
markdown += ` </a>\n`
207221
markdown += `</div>\n`
208-
markdown += `</div>\n`
209-
markdown += `</details>\n\n`
222+
223+
markdown += `</div>\n` // End details-content
224+
markdown += `</details>\n\n` // End module toggle
225+
210226
markdown += `---\n\n`
211227
})
212228
})

0 commit comments

Comments
 (0)