Fix chapter navigation to use proper numerical ordering instead of alphabetical

This commit is contained in:
2025-10-01 10:12:01 -04:00
parent b2d17bc0ac
commit f5e634fe58

View File

@@ -180,10 +180,12 @@ app.get('/books/:book', async (req, res) => {
}
// Extract chapter numbers from filenames (e.g., "Chapter_01.md" -> "1")
const chapters = chapterFiles.map(file => {
const chapterNumbers = chapterFiles.map(file => {
const match = file.match(/Chapter_(\d+)\.md$/);
return match ? parseInt(match[1], 10).toString() : null;
}).filter(Boolean);
return match ? parseInt(match[1], 10) : null;
}).filter(Boolean).sort((a, b) => a - b);
const chapters = chapterNumbers.map(num => num.toString());
res.json({ chapters, version });
} catch (error) {