diff --git a/.gitignore b/.gitignore index ed79676..c2c3b68 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ inventory.yml ansible.cfg avatars/* +thumbnails/* node_modules /build /.svelte-kit diff --git a/src/lib/components/AvatarComponent.svelte b/src/lib/components/AvatarComponent.svelte index c93d977..0575be1 100644 --- a/src/lib/components/AvatarComponent.svelte +++ b/src/lib/components/AvatarComponent.svelte @@ -6,8 +6,23 @@ let sourceSetHtml: string; $: avatarDescription = `Avatar for ${account.acct}`; $: { + // Sort thumbnails by file type. This is important, because the order of the srcset entries matter. + // We need the best format to be first + const formatPriority = new Map([ + ['avif', 0], + ['webp', 1], + ['jpg', 99], + ['jpeg', 99] + ]); + const resizedAvatars = (account.resizedAvatars ?? []).sort((a, b) => { + const extensionA = a.file.split('.').pop() ?? ''; + const extensionB = b.file.split('.').pop() ?? ''; + const prioA = formatPriority.get(extensionA) ?? 3; + const prioB = formatPriority.get(extensionB) ?? 3; + return prioA - prioB; + }); const m = new Map(); - for (const resizedAvatar of account.resizedAvatars ?? []) { + for (const resizedAvatar of resizedAvatars) { const extension = resizedAvatar.file.split('.').pop(); const mime = extension ? `image/${extension}` : 'application/octet-stream'; const sourceSetEntry = `${resizedAvatar.file} ${resizedAvatar.sizeDescriptor}`; diff --git a/src/lib/components/PostComponent.svelte b/src/lib/components/PostComponent.svelte index 2434733..a83578d 100644 --- a/src/lib/components/PostComponent.svelte +++ b/src/lib/components/PostComponent.svelte @@ -1,5 +1,6 @@