Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/changelog-1.9.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ All changes included in 1.9:
- ([#13716](https://github.com/quarto-dev/quarto-cli/issues/13716)): Fix draft pages showing blank during preview when pre-render scripts are configured.
- ([#13847](https://github.com/quarto-dev/quarto-cli/pull/13847)): Open graph title with markdown is now processed correctly. (author: @mcanouil)
- ([#13910](https://github.com/quarto-dev/quarto-cli/issues/13910)): Add support for `logo: false` to disable sidebar and navbar logos when using `_brand.yml`. Works in website projects (`sidebar.logo: false`, `navbar.logo: false`) and book projects (`book.sidebar.logo: false`, `book.navbar.logo: false`).
- ([#13951](https://github.com/quarto-dev/quarto-cli/issues/13951)): Fix `image-lazy-loading` not applying `loading="lazy"` attribute to auto-detected listing images.

### `book`

Expand Down
26 changes: 19 additions & 7 deletions src/project/types/website/listing/website-listing-read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,16 @@ export function completeListingItems(
debug(`[listing] Processing image match`);
const progressive = imgMatch[1] === "true";
const imgHeight = imgMatch[2];
const listingId = imgMatch[3];
const docRelativePath = imgMatch[4];
const lazy = imgMatch[3] !== "false";
const listingId = imgMatch[4];
const docRelativePath = imgMatch[5];
const docAbsPath = join(projectOutputDir(context), docRelativePath);
const imgPlaceholder = imagePlaceholder(
listingId,
docRelativePath,
progressive,
imgHeight,
lazy,
);
debug(`[listing] ${docAbsPath}`);
debug(`[listing] ${imgPlaceholder}`);
Expand Down Expand Up @@ -435,6 +437,7 @@ export function completeListingItems(
},
progressive,
imgHeight,
lazy,
);

debug(`[listing] replacing: ${docAbsPath}`);
Expand All @@ -454,7 +457,7 @@ export function completeListingItems(
};
fileContents = fileContents.replace(
imgPlaceholder,
imageSrc(imagePreview, progressive, imgHeight),
imageSrc(imagePreview, progressive, imgHeight, lazy),
);
} else {
debug(`[listing] using empty div: ${docAbsPath}`);
Expand Down Expand Up @@ -501,11 +504,14 @@ export function imagePlaceholder(
file: string,
progressive: boolean,
height?: string,
lazy?: boolean,
): string {
return file
? `<!-- img(9CEB782EFEE6)[progressive=${
progressive ? "true" : "false"
}, height=${height ? height : ""}]:${id}:${file} -->`
}, height=${height ? height : ""}, lazy=${
lazy === false ? "false" : "true"
}]:${id}:${file} -->`
: "";
}

Expand All @@ -517,7 +523,7 @@ const descriptionPlaceholderRegex =
/<!-- desc\(5A0113B34292\)\[max\=(.*)\]:(.*) -->/;

const imagePlaceholderRegex =
/<!-- img\(9CEB782EFEE6\)\[progressive\=(.*), height\=(.*)\]:(.*):(.*) -->/;
/<!-- img\(9CEB782EFEE6\)\[progressive\=(.*), height\=(.*), lazy\=(.*)\]:(.*):(.*) -->/;

function hydrateListing(
format: Format,
Expand Down Expand Up @@ -1202,8 +1208,14 @@ async function listItemFromFile(
}
}

function imageSrc(image: PreviewImage, progressive: boolean, height?: string) {
return `<p class="card-img-top"><img ${
function imageSrc(
image: PreviewImage,
progressive: boolean,
height?: string,
lazy?: boolean,
) {
const lazyAttr = lazy === false ? "" : "loading='lazy' ";
return `<p class="card-img-top"><img ${lazyAttr}${
progressive ? "data-src" : "src"
}="${image.src}" ${image.alt ? `alt="${image.alt}" ` : ""}${
height ? `style="height: ${height};" ` : ""
Expand Down
2 changes: 2 additions & 0 deletions src/project/types/website/listing/website-listing-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,15 @@ export function reshapeListing(
listingId: string,
itemNumber: number,
itemPath: string,
lazy?: boolean,
) => {
const pageSize = listing[kPageSize];
return imagePlaceholder(
listingId,
itemPath,
itemNumber > pageSize,
listing[kImageHeight] as string,
lazy,
);
};

Expand Down
2 changes: 1 addition & 1 deletion src/resources/projects/website/listing/item-default.ejs.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ print(`<div class="metadata-value listing-${field}">${listing.utilities.outputLi
<% if (item.image) { %>
<%= listing.utilities.img(itemNumber, item.image, "thumbnail-image", item['image-alt'], item['image-lazy-loading'] ?? listing['image-lazy-loading']) %>
<% } else { %>
<%= listing.utilities.imgPlaceholder(listing.id, itemNumber, item.outputHref) %>
<%= listing.utilities.imgPlaceholder(listing.id, itemNumber, item.outputHref, item['image-lazy-loading'] ?? listing['image-lazy-loading']) %>
<% } %>
</a></div>
```
Expand Down
2 changes: 1 addition & 1 deletion src/resources/projects/website/listing/item-grid.ejs.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ return !["title", "image", "image-alt", "date", "author", "subtitle", "descripti
<% } else { %>

```{=html}
<%= listing.utilities.imgPlaceholder(listing.id, itemNumber, item.outputHref) %>
<%= listing.utilities.imgPlaceholder(listing.id, itemNumber, item.outputHref, item['image-lazy-loading'] ?? listing['image-lazy-loading']) %>
```

<% } %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if (field === "image") {
if (item.image) {
value = listing.utilities.img(itemNumber, item[field], "", item['image-alt'], item['image-lazy-loading'] ?? listing['image-lazy-loading']);
} else {
value = listing.utilities.imgPlaceholder(listing.id, itemNumber, item.outputHref);
value = listing.utilities.imgPlaceholder(listing.id, itemNumber, item.outputHref, item['image-lazy-loading'] ?? listing['image-lazy-loading']);
}
}
return listing.utilities.outputLink(item, field, value, `listing-${field}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@ listing:
- image
image-lazy-loading: false
_quarto:
html:
ensureHtmlElements:
-
- "img[src='https://placeholder.co/100/100.png']"
- "img[src='https://placeholder.co/200/200.png']"
- "img[loading='lazy'][src='https://placeholder.co/300/300.png']"
-
- "img[loading='lazy'][src='https://placeholder.co/100/100.png']"
- "img[loading='lazy'][src='https://placeholder.co/200/200.png']"
render-project: true
tests:
html:
ensureHtmlElements:
-
- "img[src='https://placeholder.co/100/100.png']"
- "img[src='https://placeholder.co/200/200.png']"
- "img[loading='lazy'][src='https://placeholder.co/300/300.png']"
- "img[src='https://placeholder.co/400/400.png']"
- "img[src='https://placeholder.co/500/500.png']"
- "img[loading='lazy'][src='https://placeholder.co/600/600.png']"
-
- "img[loading='lazy'][src='https://placeholder.co/100/100.png']"
- "img[loading='lazy'][src='https://placeholder.co/200/200.png']"
- "img[loading='lazy'][src='https://placeholder.co/400/400.png']"
- "img[loading='lazy'][src='https://placeholder.co/500/500.png']"
---

## Hello, here's some listings with `image-lazy-loading: false`
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ listing:
- title
- image
_quarto:
render-project: true
tests:
html:
ensureHtmlElements:
-
-
- "img[loading='lazy'][src='https://placeholder.co/100/100.png']"
- "img[src='https://placeholder.co/200/200.png']"
- "img[loading='lazy'][src='https://placeholder.co/300/300.png']"
- "img[loading='lazy'][src='https://placeholder.co/400/400.png']"
- "img[src='https://placeholder.co/500/500.png']"
- "img[loading='lazy'][src='https://placeholder.co/600/600.png']"
-
- "img[loading='lazy'][src='https://placeholder.co/200/200.png']"
- "img[loading='lazy'][src='https://placeholder.co/500/500.png']"
---

## Hello, here's some listings
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@ listing:
- image
image-lazy-loading: false
_quarto:
html:
ensureHtmlElements:
-
- "img[src='https://placeholder.co/100/100.png']"
- "img[src='https://placeholder.co/200/200.png']"
- "img[loading='lazy'][src='https://placeholder.co/300/300.png']"
-
- "img[loading='lazy'][src='https://placeholder.co/100/100.png']"
- "img[loading='lazy'][src='https://placeholder.co/200/200.png']"
render-project: true
tests:
html:
ensureHtmlElements:
-
- "img[src='https://placeholder.co/100/100.png']"
- "img[src='https://placeholder.co/200/200.png']"
- "img[loading='lazy'][src='https://placeholder.co/300/300.png']"
- "img[src='https://placeholder.co/400/400.png']"
- "img[src='https://placeholder.co/500/500.png']"
- "img[loading='lazy'][src='https://placeholder.co/600/600.png']"
-
- "img[loading='lazy'][src='https://placeholder.co/100/100.png']"
- "img[loading='lazy'][src='https://placeholder.co/200/200.png']"
- "img[loading='lazy'][src='https://placeholder.co/400/400.png']"
- "img[loading='lazy'][src='https://placeholder.co/500/500.png']"
---

## Hello, here's some listings with `image-lazy-loading: false`
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ listing:
- title
- image
_quarto:
render-project: true
tests:
html:
ensureHtmlElements:
-
-
- "img[loading='lazy'][src='https://placeholder.co/100/100.png']"
- "img[src='https://placeholder.co/200/200.png']"
- "img[loading='lazy'][src='https://placeholder.co/300/300.png']"
- "img[loading='lazy'][src='https://placeholder.co/400/400.png']"
- "img[src='https://placeholder.co/500/500.png']"
- "img[loading='lazy'][src='https://placeholder.co/600/600.png']"
-
- "img[loading='lazy'][src='https://placeholder.co/200/200.png']"
- "img[loading='lazy'][src='https://placeholder.co/500/500.png']"
---

## Hello, here's some listings
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@ listing:
- image
image-lazy-loading: false
_quarto:
html:
ensureHtmlElements:
-
- "img[src='https://placeholder.co/100/100.png']"
- "img[src='https://placeholder.co/200/200.png']"
- "img[loading='lazy'][src='https://placeholder.co/300/300.png']"
-
- "img[loading='lazy'][src='https://placeholder.co/100/100.png']"
- "img[loading='lazy'][src='https://placeholder.co/200/200.png']"
render-project: true
tests:
html:
ensureHtmlElements:
-
- "img[src='https://placeholder.co/100/100.png']"
- "img[src='https://placeholder.co/200/200.png']"
- "img[loading='lazy'][src='https://placeholder.co/300/300.png']"
- "img[src='https://placeholder.co/400/400.png']"
- "img[src='https://placeholder.co/500/500.png']"
- "img[loading='lazy'][src='https://placeholder.co/600/600.png']"
-
- "img[loading='lazy'][src='https://placeholder.co/100/100.png']"
- "img[loading='lazy'][src='https://placeholder.co/200/200.png']"
- "img[loading='lazy'][src='https://placeholder.co/400/400.png']"
- "img[loading='lazy'][src='https://placeholder.co/500/500.png']"
---

## Hello, here's some listings with `image-lazy-loading: false`
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ listing:
- title
- image
_quarto:
render-project: true
tests:
html:
ensureHtmlElements:
-
-
- "img[loading='lazy'][src='https://placeholder.co/100/100.png']"
- "img[src='https://placeholder.co/200/200.png']"
- "img[loading='lazy'][src='https://placeholder.co/300/300.png']"
- "img[loading='lazy'][src='https://placeholder.co/400/400.png']"
- "img[src='https://placeholder.co/500/500.png']"
- "img[loading='lazy'][src='https://placeholder.co/600/600.png']"
-
- "img[loading='lazy'][src='https://placeholder.co/200/200.png']"
- "img[loading='lazy'][src='https://placeholder.co/500/500.png']"
---

## Hello, here's some listings
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Post 4
---

This is 4.

![](https://placeholder.co/400/400.png){.preview-image}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Post 5
image-lazy-loading: false
---

This is 5.

![](https://placeholder.co/500/500.png){.preview-image}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Post 6
image-lazy-loading: true
---

This is 6.

![](https://placeholder.co/600/600.png){.preview-image}
58 changes: 54 additions & 4 deletions tests/docs/smoke-all/listings/image-lazy-loading/listings.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,68 @@
[
{
"listing": "/blog/index.html",
"listing": "/blog/index-grid-eager.html",
"items": [
"/blog/post-1.html",
"/blog/post-2.html",
"/blog/post-3.html"
"/blog/post-3.html",
"/blog/post-4.html",
"/blog/post-5.html",
"/blog/post-6.html"
]
},
{
"listing": "/blog/index-eager.html",
"listing": "/blog/index-default.html",
"items": [
"/blog/post-1.html",
"/blog/post-2.html",
"/blog/post-3.html"
"/blog/post-3.html",
"/blog/post-4.html",
"/blog/post-5.html",
"/blog/post-6.html"
]
},
{
"listing": "/blog/index-table-eager.html",
"items": [
"/blog/post-1.html",
"/blog/post-2.html",
"/blog/post-3.html",
"/blog/post-4.html",
"/blog/post-5.html",
"/blog/post-6.html"
]
},
{
"listing": "/blog/index-grid.html",
"items": [
"/blog/post-1.html",
"/blog/post-2.html",
"/blog/post-3.html",
"/blog/post-4.html",
"/blog/post-5.html",
"/blog/post-6.html"
]
},
{
"listing": "/blog/index-default-eager.html",
"items": [
"/blog/post-1.html",
"/blog/post-2.html",
"/blog/post-3.html",
"/blog/post-4.html",
"/blog/post-5.html",
"/blog/post-6.html"
]
},
{
"listing": "/blog/index-table.html",
"items": [
"/blog/post-1.html",
"/blog/post-2.html",
"/blog/post-3.html",
"/blog/post-4.html",
"/blog/post-5.html",
"/blog/post-6.html"
]
}
]
Loading