diff --git a/backend/src/index.js b/backend/src/index.js index 46089cb0..8c42fecd 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -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) {