0.19.4: add support for proxied images

This commit is contained in:
Xylight committed 2024-06-08 17:19:30 -07:00
1 parent ac3222d987
commit 30a205cdef
3 files changed
+24 -4

No files matched your search

+1
View File
@@ -41,6 +41,7 @@ export const optimizeImageURL = (
)
return url.toString()
} catch (e) {
console.log(e)
return urlStr
}
}
@@ -1,5 +1,9 @@
<script lang="ts">
import { bestImageURL, postLink } from '$lib/components/lemmy/post/helpers.js'
import {
bestImageURL,
optimizeImageURL,
postLink,
} from '$lib/components/lemmy/post/helpers.js'
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
import { userSettings } from '$lib/settings.js'
import { isImage } from '$lib/ui/image'
@@ -25,7 +29,7 @@
tabindex="0"
>
<img
src={bestImageURL(post, true)}
src={optimizeImageURL(post.thumbnail_url || post.url || '', 128)}
loading="lazy"
class="object-cover overflow-hidden bg-slate-100 dark:bg-zinc-800 rounded-xl h-24 w-24 sm:w-32
border border-slate-200 dark:border-zinc-800 group-hover/media:border-slate-400
+17 -2
View File
@@ -12,11 +12,26 @@
export let width: number
export let res: number | undefined = undefined
const optimizeUrl = (url: string | undefined): string | undefined => {
if (url === undefined) return
const urlObj = new URL(url)
urlObj.searchParams.append('format', 'webp')
urlObj.searchParams.append(
'thumbnail',
findClosestNumber(sizes, res || width).toString()
)
return urlObj.toString()
}
$: optimizedURL = optimizeUrl(url)
</script>
{#if url}
{#if optimizedURL}
<img
src="{url}?format=webp&thumbnail={findClosestNumber(sizes, res || width)}"
src={optimizedURL}
{alt}
{width}
{title}