Skip to content

Commit

Permalink
render cover images eager apart from some on the index
Browse files Browse the repository at this point in the history
  • Loading branch information
janmonschke committed May 12, 2023
1 parent b9b66b7 commit c4ffcea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 8 additions & 2 deletions content/index.webc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ layout: layouts/base.webc
---

<ul class="index__blogPostList">
<li class="index__blogPostItem" webc:for="post of collections.blogPosts">
<li
class="index__blogPostItem"
webc:for="(post, index) of collections.blogPosts"
>
<article>
<header class="index__blogPostItemHeader">
<a :href="post.url">
<h2 class="index__blogPostTitle" @text="post.data.title"></h2>
<img @raw="post.data.coverImageHtml" alt="" webc:nokeep />
<img
@raw="index === 0 ? post.data.coverImageHtml : post.data.nonEagerCoverImageHtml"
webc:nokeep
/>
</a>
</header>
<section>
Expand Down
6 changes: 6 additions & 0 deletions eleventy.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,17 @@ module.exports = function (eleventyConfig) {
src: coverImagePath,
attributes: {
alt: blogPost.data.title,
loading: "eager",
decoding: "auto",
},
includeCaption: false,
linkToImage: false,
});

blogPost.data.nonEagerCoverImageHtml = blogPost.data.coverImageHtml
.replace('loading="eager"', 'loading="lazy"')
.replace('decoding="auto"', 'decoding="async"');

let shareMetadata = await Image(coverImagePath, {
widths: [600],
formats: ["jpeg"],
Expand Down

0 comments on commit c4ffcea

Please sign in to comment.