Commit Graph

15 Commits

Author SHA1 Message Date
kennethreitz d24903a8dc Add specific resource pages to related content and fix reading plan API
- Expand related resources with specific chapter mappings (Beatitudes, Armor of God,
  I Am Statements, Trinity, Eschatology, Soteriology, etc.)
- Click on verse text navigates to verse page (mouse users), green selection is
  keyboard-only
- Fix reading plan API import error (get_reading_text from reading_plans route)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-02 18:24:46 -05:00
kennethreitz 8ca561d591 Add Related Resources section to chapter pages with stories and topics
- Add related_content to chapter page route with topics, people, resources, and stories
- Add Bible stories matching based on verse references in story data
- Improve topic matching to use actual verse references instead of hardcoded book list
- Display Related Resources section at bottom of chapter and verse pages

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-02 18:08:47 -05:00
kennethreitz 7770c37dc5 Fix related people URLs to use correct paths
- Abraham: /family-tree/person/i60
- Jacob: /family-tree/person/i58
- David: /family-tree/person/i113
- Peter: /the-twelve-apostles/simon-peter
- John the Baptist: /biblical-prophets (no dedicated page)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-02 15:28:49 -05:00
kennethreitz 2d7e9843b0 updates to data storage 2025-11-30 21:26:59 -05:00
kennethreitz 1279fde038 Fix case-insensitive book name redirects (301)
URLs like /book/gen/chapter/1/verse/3 now properly redirect
to /book/Genesis/chapter/1/verse/3 with a 301 status.

The normalize_book_name function now does case-insensitive lookup
for both abbreviations and canonical book names.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 19:14:05 -05:00
kennethreitz 63ced29b6b Add red letter (words of Christ) to API verse endpoints
- Add red_letter field to all verse API responses
  * /api/verse/{book}/{chapter}/{verse} - single verse
  * /api/verse-range/{book}/{chapter}/{start}/{end} - verse ranges
  * /api/verse-of-the-day - daily verse

Red letter field values:
  * null - Jesus doesn't speak in this verse
  * "full" - entire verse is Jesus speaking (e.g., John 3:16)
  * "quoted text" - partial verse with exact words Jesus spoke

- Add Pydantic response models for OpenAPI documentation
  * VerseResponse - single verse with red_letter field
  * VerseRangeResponse - verse range with red_letter per verse
  * DailyVerseResponse - daily verse with red_letter
  * Includes comprehensive examples showing all red letter scenarios

- Enhance OpenAPI/Swagger documentation
  * Add detailed response examples for each endpoint
  * Multiple example scenarios (Jesus speaking, not speaking, partial)
  * Improved parameter descriptions with validation (ge=1)
  * Better endpoint summaries and descriptions

- Add comprehensive test coverage for red letter feature
  * test_red_letter_full_verse - Jesus speaks entire verse
  * test_red_letter_partial_verse - Jesus speaks part of verse
  * test_red_letter_no_words - Jesus doesn't speak
  * test_red_letter_verse_range_with_christ_words - range test
  * Update existing tests to verify red_letter field presence

All 39 API tests pass with no warnings.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 13:23:02 -05:00
kennethreitz 6df09c7665 Suppress WeasyPrint stdout/stderr noise during import
WeasyPrint outputs logging messages to stdout/stderr when imported,
which pollutes the console output. This change temporarily redirects
stdout/stderr to /dev/null during the import, then restores them.

Changes:
- Added sys and os imports
- Wrapped WeasyPrint import with stdout/stderr suppression
- Properly restore stdout/stderr in finally block

Result: Clean import with no console noise

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 12:52:21 -05:00
kennethreitz 498b191afa Migrate hardcoded data to JSON files for better maintainability
Move static reference data from Python modules to JSON files in data/ directory:
- Bible metadata (testament lists, book abbreviations) → bible_metadata.json
- Chapter explanations and popularity scores → chapter_explanations.json, popular_chapters.json
- Featured verses for verse of the day → featured_verses.json
- Resource slugs for sitemap generation → resource_slugs.json

Benefits: easier content updates, better separation of data and code, enables non-developer content management. All 252 tests passing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 17:45:26 -05:00
kennethreitz d4c364eb05 Optimize backend performance with caching and thread safety
Pre-process verse text cleaning once at initialization (5-10x speedup for iteration), fix SQLite connection thread safety for concurrent requests, and add LRU caching to frequently-called functions.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 17:33:53 -05:00
kennethreitz 7522b27e7c Implement Phase 2 performance optimizations
1. Replace regex markdown with mistune library
   - Add mistune>=3.0.2 dependency
   - Replace custom regex patterns with proper markdown parser
   - Better performance and more robust parsing
   - Supports full markdown syntax (bold, italic, strikethrough, etc.)

2. Cache story counts
   - Cache get_story_count() and get_category_count()
   - Expected: 10-20x faster story index page loads
   - Added cache invalidation to refresh_stories()

3. Fix O(n) pattern in helpers.py
   - Replace manual chapter filtering with bible.get_chapters_for_book()
   - Uses existing @lru_cache for instant lookups

Combined expected improvement: 10-20% on story pages, faster markdown

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 12:06:13 -05:00
kennethreitz 9ec7885dce Make PDF generation async to prevent event loop blocking
Convert all PDF generation endpoints from synchronous to async to
prevent blocking FastAPI's event loop during CPU-intensive operations.

Changes:
- Add render_html_to_pdf_async() using ThreadPoolExecutor (2 workers)
- Convert all PDF endpoints to async def
- Use await render_html_to_pdf_async() instead of blocking calls
- Keep render_html_to_pdf() for backward compatibility

Performance impact:
- Prevents event loop blocking during PDF generation
- Allows other requests to be processed while PDFs are rendering
- Limits concurrent PDF generation to 2 workers to control CPU usage

Files updated:
- kjvstudy_org/utils/pdf.py (new async implementation)
- kjvstudy_org/server.py (5 PDF endpoints)
- kjvstudy_org/routes/api.py (4 PDF endpoints)
- kjvstudy_org/routes/resources.py (7 PDF endpoints)
- kjvstudy_org/routes/stories.py (2 PDF endpoints)
- kjvstudy_org/routes/study_guides.py (1 PDF endpoint)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 11:44:35 -05:00
kennethreitz 9def1c4ce9 Fix Song of Solomon book name mapping (reverse direction)
Correct the book name normalization to map FROM "Song of Solomon"
TO "Solomon's Song" (the name used in verses-1769.json).

Changes:
- Reverse all Song mappings to point to "Solomon's Song"
- Update OT_BOOKS to use "Solomon's Song" (matching verses file)
- Map "Song of Solomon", "Song of Songs", and "Canticles" → "Solomon's Song"

This fixes the 404 error on /book/Song%20of%20Solomon by ensuring
that alternative names redirect to the canonical verses file name.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 09:25:52 -05:00
kennethreitz 5f52497a43 Fix Song of Solomon book name routing
Add "Solomon's Song" to BOOK_ABBREVIATIONS mapping to fix URL
routing. The KJV verses file (verses-1769.json) uses "Solomon's Song"
as the book name, but the book data uses "Song of Solomon". This
mapping ensures normalize_book_name() correctly handles the variant.

Fixes URL: https://kjvstudy.org/book/Solomon's%20Song

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 09:23:05 -05:00
kennethreitz 1156fb68e1 silly 2025-11-26 01:16:45 -05:00
kennethreitz 83df2a37ed Refactor: Split server.py into modular packages
- Create kjvstudy_org/utils/ package:
  - books.py: Book name normalization, abbreviations, testament categorization
  - helpers.py: Utility functions (create_slug, get_verse_text, etc.)
  - search.py: Full-text search with FTS5 support
  - search_index.py: SQLite FTS5 search index implementation

- Create kjvstudy_org/routes/ package:
  - api.py: All /api/* endpoints as FastAPI router

- Update server.py:
  - Import from new modular packages
  - Include API router via app.include_router()
  - Remove duplicate API routes

- Fix test_edge_cases.py to accept 404 for reversed verse ranges

All 100 tests pass.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 18:59:35 -05:00