Skip to content

Commit 6e7b1f2

Browse files
committed
xd
1 parent c6ccc81 commit 6e7b1f2

File tree

2 files changed

+36
-26
lines changed

2 files changed

+36
-26
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ jobs:
111111
raww=$(grep -Po 'MODULE\.WorkshopContent\s*=\s*(\{[^}]*\}|"[^"]*")' "$m" | head -n1 | sed -E 's/^[^=]+=\s*//' || true)
112112
feat=$(parse_list "$rawf")
113113
work=$(parse_list "$raww")
114-
# Use the actual directory name for the folder path (not the display name)
114+
# Generate slug for anchor
115+
slug=$(echo "$name" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g' | sed -E 's/^-+|-+$//g')
115116
folder="$dir"
116117
jq --arg name "$name" \
117118
--arg versionID "$uniqueid" \
@@ -120,10 +121,11 @@ jobs:
120121
--arg desc "$desc" \
121122
--arg version "$version" \
122123
--arg download "https://github.com/LiliaFramework/Modules/raw/refs/heads/gh-pages/${dir}.zip" \
123-
--arg source "../modules/${folder}/index.md" \
124+
--arg source "../modules/index.md#${slug}" \
125+
--arg folder "$folder" \
124126
--argjson features "$feat" \
125127
--argjson workshop "$work" \
126-
'. += [{name:$name,versionID:$versionID,author:$author,discord:$discord,description:$desc,version:$version,download:$download,source:$source,features:$features,workshop:$workshop}]' modules_data.json > tmp.json
128+
'. += [{name:$name,versionID:$versionID,author:$author,discord:$discord,description:$desc,version:$version,download:$download,source:$source,folder:$folder,features:$features,workshop:$workshop}]' modules_data.json > tmp.json
127129
mv tmp.json modules_data.json
128130
done
129131
- name: zip-modules
@@ -289,6 +291,9 @@ jobs:
289291
# Run the Node.js script to generate modules.md and modules/index.md
290292
if [ -f "generate_module_docs.js" ]; then
291293
node generate_module_docs.js
294+
# Cleanup individual module folders now that they are combined into the index
295+
# This prevents files from being "split" across multiple directories
296+
find documentation/docs/modules/ -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} +
292297
else
293298
echo "Error: generate_module_docs.js not found"
294299
ls -la

generate_module_docs.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ function toSlug(name) {
1414
.replace(/^-+|-$/g, '')
1515
}
1616

17+
function stripH1(content) {
18+
return content.replace(/^#\s+.*\n?/, '').trim()
19+
}
20+
1721
function getChangelog(folder) {
1822
const changelogPath = path.join(docsModulesDir, folder, 'changelog.md')
1923
if (fs.existsSync(changelogPath)) {
@@ -26,6 +30,18 @@ function getChangelog(folder) {
2630
return ''
2731
}
2832

33+
function getAbout(folder) {
34+
const aboutPath = path.join(docsModulesDir, folder, 'index.md')
35+
if (fs.existsSync(aboutPath)) {
36+
try {
37+
return fs.readFileSync(aboutPath, 'utf8')
38+
} catch (err) {
39+
console.error(`Failed to read about for ${folder}:`, err)
40+
}
41+
}
42+
return ''
43+
}
44+
2945
function main() {
3046
if (!fs.existsSync(modulesJsonPath)) {
3147
console.error('modules.json not found, skipping modules.md generation.')
@@ -80,20 +96,19 @@ function main() {
8096
const description = mod.description || 'No description available.'
8197
const features = mod.features || []
8298
const download = mod.download || '#'
83-
const sourceUrl = mod.source || ''
84-
85-
// Extract folder from source URL: ../modules/{folder}/index.md
86-
let folder = ''
87-
const match = sourceUrl.match(/\/modules\/([^/]+)\//)
88-
if (match) {
89-
folder = match[1]
90-
}
99+
const folder = mod.folder || ''
100+
const slug = toSlug(name)
91101

102+
const about = folder ? getAbout(folder) : ''
92103
const changelog = folder ? getChangelog(folder) : ''
93104

94-
markdown += `<details>\n<summary>${name}</summary>\n\n`
95-
markdown += `- **Name**: ${name}\n`
96-
markdown += `- **Description**: ${description}\n`
105+
markdown += `<details id="${slug}">\n<summary>${name}</summary>\n\n`
106+
107+
if (about) {
108+
markdown += `### About\n\n${stripH1(about)}\n\n`
109+
} else {
110+
markdown += `- **Description**: ${description}\n`
111+
}
97112

98113
if (features.length > 0) {
99114
markdown += `- **Main Features**:\n`
@@ -106,8 +121,6 @@ function main() {
106121
markdown += `- <details><summary>Changelog</summary>\n\n`
107122
markdown += `${changelog}\n\n`
108123
markdown += `</details>\n`
109-
} else {
110-
markdown += `- **Changelog**: Not available\n`
111124
}
112125

113126
markdown += `- [Download Button](${download})\n\n`
@@ -120,17 +133,9 @@ function main() {
120133
fs.writeFileSync(modulesMdPath, markdown)
121134
console.log(`Generated modules.md at ${modulesMdPath}`)
122135

123-
// Write modules/index.md
124-
let indexMarkdown = '# Modules\n\n'
125-
if (modules.length === 0) {
126-
indexMarkdown += 'No module data available. Please check back later.\n'
127-
} else {
128-
modules.forEach(mod => {
129-
indexMarkdown += `- [${mod.name || 'Unknown'}](${mod.source || ''})\n`
130-
})
131-
}
136+
// Write modules/index.md (Same content as modules.md now)
132137
fs.mkdirSync(path.dirname(modulesIndexMdPath), { recursive: true })
133-
fs.writeFileSync(modulesIndexMdPath, indexMarkdown)
138+
fs.writeFileSync(modulesIndexMdPath, markdown)
134139
console.log(`Generated modules/index.md at ${modulesIndexMdPath}`)
135140
}
136141

0 commit comments

Comments
 (0)