mirror of
https://github.com/BradNut/personal-website-sveltekit
synced 2025-09-08 23:20:18 +00:00
Using svelte-img for external image rendering on bandcamp images.
This commit is contained in:
parent
789cf00140
commit
4070922c8a
2 changed files with 23 additions and 6 deletions
|
|
@ -1,10 +1,19 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import Img from '@zerodevx/svelte-img';
|
||||||
import type { Album } from "$root/lib/types/album";
|
import type { Album } from "$root/lib/types/album";
|
||||||
|
|
||||||
|
|
||||||
export let albums: Album[];
|
export let albums: Album[];
|
||||||
const displayAlbums =
|
const displayAlbums =
|
||||||
albums?.length > 6 ? albums.slice(0, 6) : albums;
|
albums?.length > 6 ? albums.slice(0, 6) : albums;
|
||||||
|
|
||||||
|
for (let album of displayAlbums) {
|
||||||
|
album.src = [
|
||||||
|
{ format: 'avif', src: `${album.artwork}`, width: 230, height: 230 },
|
||||||
|
{ format: 'webp', src: `${album.artwork}`, width: 230, height: 230},
|
||||||
|
{ format: 'jpg', src: `${album.artwork}`, width: 230, height: 230}
|
||||||
|
]
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -19,12 +28,7 @@
|
||||||
href={album.url}
|
href={album.url}
|
||||||
rel="noreferrer"
|
rel="noreferrer"
|
||||||
>
|
>
|
||||||
<img
|
<Img src={album.src} alt={`Album art for ${album.title}`} />
|
||||||
src={`https://images.weserv.nl/?url=${encodeURIComponent(
|
|
||||||
album.artwork
|
|
||||||
)}&w=230&h=230`}
|
|
||||||
alt={`Album art for ${album.title}`}
|
|
||||||
/>
|
|
||||||
</a>
|
</a>
|
||||||
</figure>
|
</figure>
|
||||||
<a
|
<a
|
||||||
|
|
@ -81,6 +85,11 @@
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
|
figure {
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 550px) {
|
@media (max-width: 550px) {
|
||||||
grid-template-columns: 0.75fr 0.75fr;
|
grid-template-columns: 0.75fr 0.75fr;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,12 @@ export type Album = {
|
||||||
artwork: string;
|
artwork: string;
|
||||||
title: string;
|
title: string;
|
||||||
artist: string;
|
artist: string;
|
||||||
|
src?: ExternalImageSource[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ExternalImageSource = {
|
||||||
|
format: string;
|
||||||
|
src: string;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue