0.19.4: add support for proxied images
This commit is contained in:
1 parent
ac3222d987
commit
30a205cdef
3 files changed
+24
-4
No files matched your search
@@ -41,6 +41,7 @@ export const optimizeImageURL = (
|
|||||||
)
|
)
|
||||||
return url.toString()
|
return url.toString()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
return urlStr
|
return urlStr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
<script lang="ts">
|
<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 { showImage } from '$lib/components/ui/ExpandableImage.svelte'
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { userSettings } from '$lib/settings.js'
|
||||||
import { isImage } from '$lib/ui/image'
|
import { isImage } from '$lib/ui/image'
|
||||||
@@ -25,7 +29,7 @@
|
|||||||
tabindex="0"
|
tabindex="0"
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
src={bestImageURL(post, true)}
|
src={optimizeImageURL(post.thumbnail_url || post.url || '', 128)}
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
class="object-cover overflow-hidden bg-slate-100 dark:bg-zinc-800 rounded-xl h-24 w-24 sm:w-32
|
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
|
border border-slate-200 dark:border-zinc-800 group-hover/media:border-slate-400
|
||||||
|
|||||||
@@ -12,11 +12,26 @@
|
|||||||
|
|
||||||
export let width: number
|
export let width: number
|
||||||
export let res: number | undefined = undefined
|
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>
|
</script>
|
||||||
|
|
||||||
{#if url}
|
{#if optimizedURL}
|
||||||
<img
|
<img
|
||||||
src="{url}?format=webp&thumbnail={findClosestNumber(sizes, res || width)}"
|
src={optimizedURL}
|
||||||
{alt}
|
{alt}
|
||||||
{width}
|
{width}
|
||||||
{title}
|
{title}
|
||||||
|
|||||||
Reference in new issue
Block a user