Skip to content

Speed up news by using webp for images - #377

Merged
biodranik merged 1 commit into
masterfrom
ab/webp
Nov 18, 2026
Merged

biodranik merged 1 commit into
masterfrom
ab/webp

Conversation

@biodranik

Copy link
Copy Markdown
Member

Left old image previews to avoid introducing redirects.

@biodranik
biodranik requested a review from vng November 17, 2026 13:34

@vng vng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of the WebP migration. CI is green: Zola build, translations, DCO and Pages all pass.

Verified correct

  • og:image sources are unchanged. I recomputed them for all 1,181 news Markdown files on master and on HEAD (explicit preview_image → parent cover → first sorted image) and found 0 changes. All referenced files still exist.
  • No in-repo link points to any of the 65 deleted originals.

Actionable (this PR)

  1. base.html WebP→original swap is dead code: no real content triggers it. Drop it (inline).
  2. _news_media.html: drop the news_image_variant component and the alt fallback, which no content uses. Replace them with a single twin-membership skip, which also catches mistakes by failing the build (inline suggestion).
  3. _news_preview.html: the WebP parent cover isn't used. Revert it, or simplify the nested loop and flag (inline).
  4. test_redirect_limits_and_order is left over from the removed redirect step and is out of scope here (inline).
  5. Docs: CLAUDE.md § Preview Images (lines 212-214) still says NNN-preview.jpg is "this exact filename convention". It also says "first JPEG/PNG/WebP asset". It needs the twin rule: a retained original stays the preview URL, and the gallery and Telegram show its WebP once. If the -preview.webp support stays, CLAUDE.md should mention it too.
  6. Commits: the three commits describe intermediate states that no longer exist. 60f3cd9 mentions a "repeatable conversion tool" and a static derivative lookup, and 5353cf0 mentions "permanent redirects". Please squash them into one commit whose message describes only the final result: 65 originals replaced, 42 preview originals kept beside WebP twins, and no redirects.

Trade-off to confirm (not a bug)

  • The 65 deleted JPEG/PNG gallery URLs now return 404, multiplied across every localized slug path. That fits the "no redirects" decision. Externally hot-linked or image-search-indexed copies will break, but that seems acceptable for gallery images.

No pre-existing issues found that need a separate PR.


Generated by Claude Code

Comment thread templates/_news_media.html Resolved
Comment thread templates/base.html Resolved
Comment thread templates/_news_preview.html Resolved
Comment thread tools/test_navigation.py Resolved
Comment thread tools/telegram_post_all.py Resolved
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Deploying organicmaps with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7ca407b
Status: ✅  Deploy successful!
Preview URL: https://5fdd6001.organicmaps.pages.dev
Branch Preview URL: https://ab-webp.organicmaps.pages.dev

View logs

@biodranik
biodranik requested a review from vng November 17, 2026 23:01

@vng vng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 956a05e (rebased on master, 1 commit). I found no correctness issues. The three inline comments are optional: one fail-fast check and two docs cleanups.

Checked against master with Zola 0.23.4:

  • og:image is identical on all 3,536 rendered pages. The ˋ<image:loc>ˋ entries in the sitemap are identical too, so shared preview URLs keep working with no redirects.
  • None of the 65 deleted originals is referenced from content/, templates/, static/ or tools/. All 198 rendered /news/… image URLs resolve to files in public/.
  • Each of the 42 retained JPEG/PNG originals with a .webp sibling is a current og:image, so none is dead weight. Each of the 107 added WebP files is smaller than its original.
  • tools/test_navigation.py (8 tests) and npm test pass. CI is green.
  • The previous five review threads are already resolved, and their suggestions are reflected in the code. Nothing is left to resolve.

Inline (fix here, optional):

  1. templates/_news_media.html:28: fail the build when a JPEG/PNG that has a WebP sibling isn't the sharing preview. This enforces the README's "no JPEG/PNG duplicates" rule. Verified: the build output is unchanged, and adding a stray duplicate fails the build.
  2. README.md:110-112: duplicate sentence, and the cover example still uses .jpg for a new post.
  3. README.md:74-80: repeats the retained-preview and no-redirect rule from lines 59-63.

Pre-existing / out of scope: none worth a separate PR. The deleted gallery originals' old URLs now return 404. That matches the PR description, which keeps only the shared previews, and nothing in the site links to them.


Generated by Claude Code

{#- Keep sharing previews published and show their WebP siblings in the gallery. -#}
{%- if extension != "webp" -%}
{%- set webp_path = (media | trim_end(pat=filename_extension)) ~ "webp" -%}
{%- if webp_path in resource.assets -%}{%- continue -%}{%- endif -%}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional fail-fast (new in this PR): README says "Do not add JPEG/PNG duplicates" for new posts, but nothing enforces it. A stray X.jpg next to X.webp is hidden here without any warning and still gets published. All 42 retained originals are currently the sharing preview: either the first image asset (first_image is still true when the hidden original is reached) or extra.preview_image (for example 630/02-bookmarks-tracks-multi-selection.jpg). Throwing for anything else turns the convention into a build check:

Suggested change
{%- if webp_path in resource.assets -%}{%- continue -%}{%- endif -%}
{%- if webp_path in resource.assets -%}
{#- Only a published sharing preview may keep its original next to its WebP. -#}
{%- if not first_image and filename != resource.extra | get(key="preview_image", default="") -%}
{{- throw(message="'" ~ media ~ "' duplicates its WebP sibling and is not the sharing preview") -}}
{%- endif -%}
{%- continue -%}
{%- endif -%}

I checked this with Zola 0.23.4. Applied to this branch, the full build output is byte-identical (diff -rq is empty). Adding 630/03-hide-track-in-list.jpg next to its WebP fails the build. It's lenient in one case: a hidden first original in a post that also has a parent -preview cover. If you take it, add a negative subtest to test_navigation.py next to the invalid_alt_key cases.


Generated by Claude Code

Comment thread README.md Resolved
Comment thread README.md Resolved
Add 107 optimized WebP images, replacing 65 gallery originals and
keeping 42 published JPEG and PNG previews alongside their WebP
siblings. Serve the retained previews at their published URLs.

Use the lowercase .webp sibling in news galleries and Telegram albums.
Key image descriptions by the gallery filename. Allow dedicated WebP
sharing covers and give existing JPEG covers priority.

Verified with Zola 0.23.6, eight navigation tests, and npm test.

Signed-off-by: Alexander Borsuk <me@alex.bio>
@biodranik
biodranik merged commit 03a7e35 into master Nov 18, 2026
4 checks passed
@biodranik
biodranik deleted the ab/webp branch November 18, 2026 07:32

This branch was successfully deployed

1 active deployment
production — 7ca407b8 Deployed Nov 17, 2026 by biodranik via Check Zola build #1287
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.

2 participants