feat: allow path params for verse navigation
This commit is contained in:
+32
-2
@@ -555,8 +555,38 @@ def extract_verses(soup: BeautifulSoup, max_canto=99, max_chapter=999, max_verse
|
||||
if state == "SUMMARY":
|
||||
continue
|
||||
|
||||
# --- TEXT N header (p21) ---
|
||||
# --- TEXT N header (p21) — authoritative verse number ---
|
||||
# The p20 reference sometimes has wrong verse numbers (duplicates).
|
||||
# The p21 TEXT header always has the correct verse number.
|
||||
if cls == TEXT_HEADER_CLASS and current_verse:
|
||||
m = re.match(r"TEXTS?\s+(\d+)(?:\s*[-–]\s*(\d+))?", text, re.IGNORECASE)
|
||||
if m:
|
||||
correct_verse = int(m.group(1))
|
||||
correct_end = int(m.group(2)) if m.group(2) else None
|
||||
|
||||
# Fix the verse number if p20 was wrong
|
||||
if current_verse["verse"] != correct_verse:
|
||||
current_verse["verse"] = correct_verse
|
||||
|
||||
# Fix verse_end
|
||||
if correct_end is not None:
|
||||
current_verse["verse_end"] = correct_end
|
||||
elif (
|
||||
"verse_end" in current_verse
|
||||
and current_verse.get("verse_end") != correct_end
|
||||
):
|
||||
if correct_end is None and "verse_end" in current_verse:
|
||||
del current_verse["verse_end"]
|
||||
|
||||
# Rebuild the clean reference with corrected numbers
|
||||
canto = current_verse["canto"]
|
||||
chapter = current_verse["chapter"]
|
||||
if correct_end is not None:
|
||||
current_verse["reference"] = (
|
||||
f"SB {canto}.{chapter}.{correct_verse}-{correct_end}"
|
||||
)
|
||||
else:
|
||||
current_verse["reference"] = f"SB {canto}.{chapter}.{correct_verse}"
|
||||
continue
|
||||
|
||||
# --- TEXT label (p22) ---
|
||||
@@ -691,7 +721,7 @@ def write_json(data, filepath):
|
||||
def main():
|
||||
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
html_path = os.path.join(base_dir, "public", "html", "sb.html")
|
||||
output_dir = os.path.join(base_dir, "app", "lib", "books", "sb")
|
||||
output_dir = os.path.join(base_dir, "lib", "jsons", "books", "sb")
|
||||
|
||||
print(f"Reading {html_path}...")
|
||||
with open(html_path, "r", encoding="utf-8") as f:
|
||||
|
||||
Reference in New Issue
Block a user