Skip to content

Gutenberg: rewrite every cover link in a book's HTML head - #177

Open
pawank925 wants to merge 2 commits into
openzim:mainfrom
pawank925:issue-176-gutenberg-icon-links
Open

pawank925 wants to merge 2 commits into
openzim:mainfrom
pawank925:issue-176-gutenberg-icon-links

Conversation

@pawank925

@pawank925 pawank925 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

changes

update_html_for_static used soup.find("link", rel="icon"), so only the first <link rel="icon"> of a book's HTML page got the {book_id}/ prefix. Some Gutenberg books repeat the cover tag — book 77225 has two identical <link href="images/cover_front.jpg" rel="icon" type="image/x-cover"> entries under different auto-generated ids — and the extra ones were left pointing at images/cover_front.jpg.webp, outside the book's own folder. That is what makes zimcheck fail on those ZIMs.

The loop now uses find_all, so every icon link is rewritten. _cover_href (used by cover detection) is still filled only once, by the first icon link that has an href.

.webp was already appended to all of them — that part comes from rewrite_html_image_references, which already used find_all; only the prefix was missing, which matches the screenshot in the issue.

Tests

  • Two new cases in scraper/tests/test_gutenberg_rewriter.py: the repeated-tag head copied from 77225 (both links must end up as 11/images/cover_front.jpg.webp) and a head whose icon links are not local assets (anchor/missing href are left untouched and do not poison _cover_href).
  • Checked against the real page: pg77225-images.html downloaded from Gutenberg and passed through update_html_for_static with a 77225 work now rewrites both icon links to 77225/images/cover_front.jpg.webp.
  • Full scraper suite: 629 passed. lint-black, lint-ruff and check-pyright clean.

fixes #176

@codecov

codecov Bot commented Nov 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.92%. Comparing base (ae005d3) to head (a50fd86).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #177      +/-   ##
==========================================
+ Coverage   77.83%   77.92%   +0.08%     
==========================================
  Files          68       68              
  Lines        4502     4502              
  Branches      725      725              
==========================================
+ Hits         3504     3508       +4     
  Misses        793      793              
+ Partials      205      201       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gutenberg: not all link URLs are rewritten in head of book HTML version

1 participant