Fix verse sitemap generation - suppress WeasyPrint warnings

The sitemap-verses.xml file was contaminated with WeasyPrint import
warnings, causing "Document is empty" errors in Google Search Console.

Fixes:
- Suppress stdout/stderr during imports to prevent warnings in output
- Add error handling to sitemap-verses endpoint
- Regenerate clean sitemap-verses.xml (6.3MB, 31,102 verses)

The file now starts with proper XML declaration instead of error messages.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-27 19:37:34 -05:00
parent f9ce3861ff
commit 3493c43144
3 changed files with 25 additions and 10 deletions
+12 -1
View File
@@ -81,10 +81,21 @@ def sitemap_index():
@router.get("/sitemap-verses.xml")
def sitemap_verses():
"""Serve static verse sitemap (31,102 verses, generated once)"""
# Check if file exists
if not _VERSE_SITEMAP_PATH.exists():
return Response(
content=f"Verse sitemap not found at {_VERSE_SITEMAP_PATH}",
status_code=404,
media_type="text/plain"
)
return FileResponse(
path=_VERSE_SITEMAP_PATH,
media_type="application/xml",
headers={"Cache-Control": "public, max-age=86400"} # Cache for 1 day
headers={
"Cache-Control": "public, max-age=86400", # Cache for 1 day
"Content-Encoding": "identity" # Explicitly say it's not compressed
}
)
-9
View File
@@ -1,12 +1,3 @@
-----
WeasyPrint could not import some external libraries. Please carefully follow the installation steps before reporting an issue:
https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#installation
https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#troubleshooting
-----
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
+13
View File
@@ -26,13 +26,26 @@ Usage:
git commit -m "Update verse sitemap"
"""
import sys
import os
from pathlib import Path
# Suppress WeasyPrint warnings during import
# Redirect stdout temporarily to suppress import warnings
from io import StringIO
old_stdout = sys.stdout
old_stderr = sys.stderr
sys.stdout = StringIO()
sys.stderr = StringIO()
# Add parent directory to path to import kjv module
sys.path.insert(0, str(Path(__file__).parent.parent))
from kjvstudy_org.kjv import bible
# Restore stdout/stderr
sys.stdout = old_stdout
sys.stderr = old_stderr
def generate_verse_sitemap():
"""Generate sitemap XML for all verses in the Bible."""