pronounscc/frontend/src/lib/components/FallbackImage.svelte

30 lines
853 B
Svelte
Raw Normal View History

2023-03-11 16:52:48 +01:00
<script lang="ts">
export let urls: string[];
2023-03-11 16:52:48 +01:00
export let alt: string;
export let width = 300;
2023-03-11 16:52:48 +01:00
const contentTypeFor = (url: string) => {
if (url.endsWith(".webp")) {
return "image/webp";
} else if (url.endsWith(".jpg") || url.endsWith(".jpeg")) {
return "image/jpeg";
} else if (url.endsWith(".png")) {
return "image/png";
} else {
return "application/octet-stream";
}
};
</script>
{#if urls.length > 0}
2023-03-11 16:52:48 +01:00
<picture class="rounded-circle img-fluid">
{#each urls as url}
<source {width} srcSet={url} type={contentTypeFor(url)} />
2023-03-11 16:52:48 +01:00
{/each}
<img {width} src={urls[0]} {alt} class="rounded-circle img-fluid" />
2023-03-11 16:52:48 +01:00
</picture>
{:else}
<!-- TODO: actual placeholder that isn't a cat -->
<img {width} class="rounded-circle img-fluid" src="https://placekitten.com/512/512" {alt} />
2023-03-11 16:52:48 +01:00
{/if}