From 5f22fb5bdc09f08d7bfd7c76034fc9e7370b06b2 Mon Sep 17 00:00:00 2001 From: Ryderjj89 Date: Mon, 15 Sep 2025 17:40:37 -0400 Subject: [PATCH] Fix search functionality for markdown bible data - Update search engine to parse numbered list format (1. verse text) - Fix chapter file path construction to use Chapter_XX.md format - Add zero-padding for chapter numbers in API routes - Skip empty lines and headers in markdown parsing - Ensure compatibility with external bible data source structure --- backend/src/index.js | 4 +++- backend/src/search.js | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/backend/src/index.js b/backend/src/index.js index c94f8f16..25673bd3 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -126,7 +126,9 @@ app.get('/books/:book', async (req, res) => { app.get('/books/:book/:chapter', async (req, res) => { try { const { book, chapter } = req.params; - const chapterPath = path.join(BIBLE_DATA_DIR, book, `${chapter}.md`); + // Format chapter number with leading zero if needed (e.g., "1" -> "01") + const paddedChapter = chapter.padStart(2, '0'); + const chapterPath = path.join(BIBLE_DATA_DIR, book, `Chapter_${paddedChapter}.md`); const content = await readMarkdownFile(chapterPath); res.type('text/markdown').send(content); diff --git a/backend/src/search.js b/backend/src/search.js index ff663169..048fec9a 100644 --- a/backend/src/search.js +++ b/backend/src/search.js @@ -16,8 +16,16 @@ class BibleSearchEngine { for (let i = 0; i < lines.length; i++) { const line = lines[i].trim(); - // Match verse patterns like "1 In the beginning..." or "**1** In the beginning..." - const verseMatch = line.match(/^(\*\*)?(\d+)(\*\*)?\s+(.+)$/); + // Skip empty lines and headers + if (!line || line.startsWith('#')) { + continue; + } + + // Match verse patterns: + // - "1. In the beginning..." (numbered list format) + // - "1 In the beginning..." (simple number format) + // - "**1** In the beginning..." (bold number format) + const verseMatch = line.match(/^(\*\*)?(\d+)(\*\*)?[.\s]\s*(.+)$/); if (verseMatch) { const verseNumber = parseInt(verseMatch[2]);