feat: Video covers support + fetchpriority tuning for LCP covers#1787
Open
Void4m0n wants to merge 10 commits intojerryc127:devfrom
Open
feat: Video covers support + fetchpriority tuning for LCP covers#1787Void4m0n wants to merge 10 commits intojerryc127:devfrom
Void4m0n wants to merge 10 commits intojerryc127:devfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Context
Hi! I know this PR doesn’t align with the simplicity-first direction Jerry wants to follow as stated on #1774 (comment). I implemented it for my own blog and I’m sharing it in case it is useful to others. Jerry, feel free to close the PR.
This PR is already implemented on my personal blog https://void4m0n.com/
Motivation
I wanted to add more dynamism to my blog. Since Butterfly didn’t support video covers, I initially used GIFs, but they are not optimal for performance or user experience. Using video instead of GIF is generally recommended, so I implemented video cover support across the theme’s cover slots.
Separately, I noticed that with Lazy mode enabled, some above-the-fold covers (part of the LCP) were still treated as lazy-loaded, negatively impacting Web Core Vitals. This PR also adds a small configuration option to prioritize the first N covers.
Video cover support and fallbacks
What changed
This PR extends the existing cover system to support
videoin addition to the current behavior (img/ CSS background string), across:cover(main page)pagination_cover(post page)related_post(post page)recent_post(main page)article_sort(articles page)Supported video formats (auto-detected)
Video support is auto-detected from the cover value (no manual type selection):
.mp4and.webmWhen detected as video, the theme renders
<video><source></video>and setscover_mimeautomatically:.webm->video/webmvideo/mp4Configurable video parameters (YAML examples)
Video rendering always includes:
muted,playsinlineautoplay,loop&posterare User-configurable parameters provided via*_video_parametersobjects. Example (main cover):Section-specific examples:
Parameter workflow (inheritance / overrides)
Per-section overrides are supported via
*_video_parameters, even if a section-specific cover is not defined.*_video_parameters, it is usedcover_video_parameters(per-parameter inheritance)No-cover behavior (
false)false:cover,recent_post,article_sortfalse:pagination,related_postSection cover fallback (when a section cover is missing)
If the section cover is not provided, the renderer falls back to the post’s main
covervalue:pagination_coverisundefined, it falls back tocoverrelated_post_coverisundefined, it falls back tocoverrecent_post_cover,article_sort_cover) when they are not explicitly definedThis preserves the existing theme behavior: section-specific covers are optional overrides, and when they are not set the main
coveris used as before.LCP_Optimization
With Lazy mode enabled, covers that end up being part of the LCP could still be treated as lazy-loaded, negatively impacting Web Core Vitals. This PR adds an option under
LCP_Optimizationto prioritize the first N covers (above-the-fold) so they are not affected by lazy-loading behavior.How it works
loading="eager"andfetchpriority="high"(anddecoding="async"is avoided for eager items).<link rel="preload" as="image" href="...poster..." fetchpriority="high">Note about preload placement
Ideally, the preload
<link>should live in the document<head>so the browser can discover it as early as possible. In this implementation it is kept close to the cover markup to preserve simplicity and avoid introducing global head-injection logic, while still providing the intended effect: Web Core Vitals/Lighthouse no longer report the missing-preload warning for the LCP resource, which may translate into improved scoring while keeping the implementation straightforward.Additional fix (unrelated to video covers)
onerrorfallback to the related posts<img>cover:onerror="this.onerror=null;this.src='...'"TODO
If this PR is of interest, it may be worth adding a fallback for cases where a section-specific cover is configured but the referenced file does not exist. It is not fully clear to me whether the best target should be the
404.jpgimage, or falling back to the basecover.My preference would be to fall back to the
404.jpg, since the user explicitly configured a section-specific cover and the requested asset is missing. That said, falling back to the basecoverwould also be a reasonable choice, depending on the desired UX.Extra Comments
Sorry for the many commits. I wanted to keep this PR as close as possible to the style used in the theme, and since I’ve been working on it in short sessions, I occasionally lost track of what I was changing and ended up committing more often than intended. Thanks, Jerry, for developing and maintaining this beautiful theme.