Fix chapter listing API and restore font size controls

This commit is contained in:
Ryderjj89
2025-09-13 15:59:07 -04:00
parent 1750b7c4ae
commit 9bebd76d7c
4 changed files with 46 additions and 36 deletions

View File

@@ -96,15 +96,13 @@ app.get('/books/:book', async (req, res) => {
return res.status(404).json({ error: `No chapters found for book '${book}'` });
}
// Combine all chapters
let fullBook = `# ${book}\n\n`;
for (const chapterFile of chapterFiles) {
const chapterPath = path.join(bookDir, chapterFile);
const chapterContent = await readMarkdownFile(chapterPath);
fullBook += chapterContent + '\n\n';
}
// Extract chapter numbers from filenames (e.g., "Chapter_01.md" -> "1")
const chapters = chapterFiles.map(file => {
const match = file.match(/Chapter_(\d+)\.md$/);
return match ? parseInt(match[1], 10).toString() : null;
}).filter(Boolean);
res.type('text/markdown').send(fullBook);
res.json({ chapters });
} catch (error) {
res.status(404).json({ error: `Book '${req.params.book}' not found` });
}