Skip to content

Commit ea3b5ed

Browse files
committed
fix: resolve favicon images properly
Fixes #4443
1 parent 85147c8 commit ea3b5ed

File tree

39 files changed

+128
-109
lines changed

39 files changed

+128
-109
lines changed

fixtures/ssg-netlify-by-project-id/app/constants.mjs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ export const imageLoader = (props) => {
2424
}
2525

2626
// https://docs.netlify.com/image-cdn/overview/
27-
return (
28-
"/.netlify/images?url=" +
29-
encodeURIComponent(props.src) +
30-
"&w=" +
31-
props.width +
32-
"&q=" +
33-
props.quality
34-
);
27+
const searchParams = new URLSearchParams();
28+
searchParams.set("url", props.src);
29+
searchParams.set("w", props.width.toString());
30+
if (props.height) {
31+
searchParams.set("h", props.height.toString());
32+
}
33+
searchParams.set("q", props.quality.toString());
34+
// fit=contain by default
35+
return `/.netlify/images?${searchParams}`;
3536
};

fixtures/ssg-netlify-by-project-id/pages/index/+Head.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const Head = ({ data }: { data: PageContext["data"] }) => {
6060
<link
6161
rel="icon"
6262
href={imageLoader({
63-
src: favIconAsset.name,
63+
src: `${assetBaseUrl}${favIconAsset.name}`,
6464
// width,height must be multiple of 48 https://developers.google.com/search/docs/appearance/favicon-in-search
6565
width: 144,
6666
height: 144,

fixtures/ssg/pages/another-page/+Head.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const Head = ({ data }: { data: PageContext["data"] }) => {
6060
<link
6161
rel="icon"
6262
href={imageLoader({
63-
src: favIconAsset.name,
63+
src: `${assetBaseUrl}${favIconAsset.name}`,
6464
// width,height must be multiple of 48 https://developers.google.com/search/docs/appearance/favicon-in-search
6565
width: 144,
6666
height: 144,

fixtures/ssg/pages/index/+Head.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const Head = ({ data }: { data: PageContext["data"] }) => {
6060
<link
6161
rel="icon"
6262
href={imageLoader({
63-
src: favIconAsset.name,
63+
src: `${assetBaseUrl}${favIconAsset.name}`,
6464
// width,height must be multiple of 48 https://developers.google.com/search/docs/appearance/favicon-in-search
6565
width: 144,
6666
height: 144,

fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export const links: LinksFunction = () => {
205205
result.push({
206206
rel: "icon",
207207
href: imageLoader({
208-
src: favIconAsset.name,
208+
src: `${assetBaseUrl}${favIconAsset.name}`,
209209
// width,height must be multiple of 48 https://developers.google.com/search/docs/appearance/favicon-in-search
210210
width: 144,
211211
height: 144,

fixtures/webstudio-cloudflare-template/app/routes/_index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export const links: LinksFunction = () => {
205205
result.push({
206206
rel: "icon",
207207
href: imageLoader({
208-
src: favIconAsset.name,
208+
src: `${assetBaseUrl}${favIconAsset.name}`,
209209
// width,height must be multiple of 48 https://developers.google.com/search/docs/appearance/favicon-in-search
210210
width: 144,
211211
height: 144,

fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export const links: LinksFunction = () => {
205205
result.push({
206206
rel: "icon",
207207
href: imageLoader({
208-
src: favIconAsset.name,
208+
src: `${assetBaseUrl}${favIconAsset.name}`,
209209
// width,height must be multiple of 48 https://developers.google.com/search/docs/appearance/favicon-in-search
210210
width: 144,
211211
height: 144,

fixtures/webstudio-custom-template/app/routes/[world]._index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export const links: LinksFunction = () => {
205205
result.push({
206206
rel: "icon",
207207
href: imageLoader({
208-
src: favIconAsset.name,
208+
src: `${assetBaseUrl}${favIconAsset.name}`,
209209
// width,height must be multiple of 48 https://developers.google.com/search/docs/appearance/favicon-in-search
210210
width: 144,
211211
height: 144,

fixtures/webstudio-custom-template/app/routes/_index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export const links: LinksFunction = () => {
205205
result.push({
206206
rel: "icon",
207207
href: imageLoader({
208-
src: favIconAsset.name,
208+
src: `${assetBaseUrl}${favIconAsset.name}`,
209209
// width,height must be multiple of 48 https://developers.google.com/search/docs/appearance/favicon-in-search
210210
width: 144,
211211
height: 144,

fixtures/webstudio-remix-netlify-edge-functions/app/constants.mjs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ export const imageLoader = (props) => {
1818
}
1919

2020
// https://docs.netlify.com/image-cdn/overview/
21-
return (
22-
"/.netlify/images?url=" +
23-
encodeURIComponent(props.src) +
24-
"&w=" +
25-
props.width +
26-
"&q=" +
27-
props.quality
28-
);
21+
const searchParams = new URLSearchParams();
22+
searchParams.set("url", props.src);
23+
searchParams.set("w", props.width.toString());
24+
if (props.height) {
25+
searchParams.set("h", props.height.toString());
26+
}
27+
searchParams.set("q", props.quality.toString());
28+
// fit=contain by default
29+
return `/.netlify/images?${searchParams}`;
2930
};

0 commit comments

Comments
 (0)