md: fix image handling

This commit is contained in:
Xylight committed 2024-08-03 18:24:28 -07:00
1 parent bcc3c48f27
commit fe7898fa3c
4 files changed
+22 -12

No files matched your search

+9 -4
View File
@@ -36,10 +36,10 @@ export const optimizeImageURL = (
try {
const url = new URL(urlStr)
url.searchParams.append('format', 'webp')
if (!url.searchParams.has('format')) url.searchParams.set('format', 'webp')
if (width > 0) {
url.searchParams.append(
if (width > 0 && !url.searchParams.has('thumbnail')) {
url.searchParams.set(
'thumbnail',
findClosestNumber(
[128, 196, 256, 512, 728, 1024, 1536],
@@ -48,6 +48,10 @@ export const optimizeImageURL = (
)
}
if (width == -1) {
url.searchParams.delete('thumbnail')
}
return url.toString()
} catch (e) {
console.log(e)
@@ -74,7 +78,8 @@ export const mediaType = (url?: string, view: View = 'cozy'): MediaType => {
if (isImage(url)) return 'image'
if (isVideo(url)) return 'iframe'
if (isYoutubeLink(url)) return 'iframe'
return 'embed'
if (URL.canParse(url)) return 'embed'
return 'none'
}
return 'none'