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
15 changes: 14 additions & 1 deletion fixtures/react-router-docker/app/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@
*/
export const assetBaseUrl = "/assets/";

/**
* URL.canParse(props.src)
* @type {(url: string) => boolean}
*/
const UrlCanParse = (url) => {
try {
new URL(url);
return true;
} catch {
return false;
}
};

/**
* @type {import("@webstudio-is/image").ImageLoader}
*/
Expand All @@ -12,7 +25,7 @@ export const imageLoader = (props) => {
return props.src;
}
// handle absolute urls
const path = URL.canParse(props.src) ? `/${props.src}` : props.src;
const path = UrlCanParse(props.src) ? `/${props.src}` : props.src;
// https://github.com/unjs/ipx?tab=readme-ov-file#modifiers
return `/_image/w_${props.width},q_${props.quality}${path}`;
};
15 changes: 14 additions & 1 deletion packages/cli/templates/react-router-docker/app/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@
*/
export const assetBaseUrl = "/assets/";

/**
* URL.canParse(props.src)
* @type {(url: string) => boolean}
*/
const UrlCanParse = (url) => {
try {
new URL(url);
return true;
} catch {
return false;
}
};

/**
* @type {import("@webstudio-is/image").ImageLoader}
*/
Expand All @@ -12,7 +25,7 @@ export const imageLoader = (props) => {
return props.src;
}
// handle absolute urls
const path = URL.canParse(props.src) ? `/${props.src}` : props.src;
const path = UrlCanParse(props.src) ? `/${props.src}` : props.src;
// https://github.com/unjs/ipx?tab=readme-ov-file#modifiers
return `/_image/w_${props.width},q_${props.quality}${path}`;
};
Loading