bug: Fix issue with page links going to the wrong place

This commit is contained in:
2026-06-08 21:48:52 +00:00
parent 4dbdb12876
commit 41d89cb632
7 changed files with 21072 additions and 23602 deletions

17
pages.py Normal file
View File

@@ -0,0 +1,17 @@
import pathlib
import re
PAGE_RGX = r"page ([0-9]+)"
# for root, dirs, files in pathlib.Path("./books/core").walk():
for root, dirs, files in pathlib.Path("./books/natural-fantasy-atlas").walk():
files = [root / fn for fn in files if fn.endswith(".html")]
for fn in files:
with fn.open() as fh:
html = fh.read()
with fn.open('w') as fh:
for line in html.split("\n"):
if re.search(PAGE_RGX, line) and "</a" not in line:
line = re.sub(PAGE_RGX, r'<a href="/books/natural-fantasy-atlas/#page-\1">\g<0></a>', line)
fh.write(line)