Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix preload image link behavior for covers array and single cover #385

Merged
merged 1 commit into from
Jan 21, 2025

Conversation

szNightFury
Copy link
Contributor

@szNightFury szNightFury commented Jan 20, 2025

When preloading cover images in the header, there are two issues with the current implementation:

  1. For multiple covers (array), the href attribute contains the entire array stringified rather than individual image URLs:
<!-- Current incorrect output -->
<link rel="preload" href="[&quot;https://example.com/1.jpg&quot;,&quot;https://example.com/2.jpg&quot;]" as="image">
  1. For a single cover (string), the string is incorrectly iterated character by character, resulting in multiple preload links for each character:
<!-- Current incorrect output -->
<link rel="preload" href="/" as="image">
<link rel="preload" href="c" as="image">
<link rel="preload" href="o" as="image">
<link rel="preload" href="v" as="image">

Expected Behavior

  • For multiple covers: Each image URL should have its own preload link
  • For single cover: Should only generate one preload link for the entire URL

Proposed Solution

Update the template logic to handle both array and string cases:

if enablePreload && enableCover
    if enableFixedCover
        link(rel="preload" href=theme.homeConfig.fixedCover as="image" fetchpriority="high")
    else if Array.isArray(covers)
        each image in covers
            link(rel="preload" href!=image as="image" fetchpriority="high")
    else
        link(rel="preload" href!=covers as="image" fetchpriority="high")

Signed-off-by: Tenglong Li <100794088+szNightFury@users.noreply.github.com>
@zkz098 zkz098 merged commit a12728f into theme-shoka-x:main Jan 21, 2025
3 checks passed
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