diff --git a/src/lib/components/lemmy/Post.svelte b/src/lib/components/lemmy/Post.svelte index c40119a3..18e043c7 100644 --- a/src/lib/components/lemmy/Post.svelte +++ b/src/lib/components/lemmy/Post.svelte @@ -17,7 +17,7 @@ } from 'svelte-hero-icons' import RelativeDate from '$lib/components/util/RelativeDate.svelte' import CommunityLink from '$lib/components/community/CommunityLink.svelte' - import { isImage } from '$lib/ui/image.js' + import { isImage, isVideo } from '$lib/ui/image.js' import { authData, getClient } from '$lib/lemmy.js' import PostVote from '$lib/components/lemmy/PostVote.svelte' import FormattedNumber from '$lib/components/util/FormattedNumber.svelte' @@ -91,6 +91,13 @@ loading="lazy" /> + {:else if isVideo(postRes.post.url)} + + + + {/if} {#if postRes.post.body}
diff --git a/src/lib/ui/image.ts b/src/lib/ui/image.ts index 520abeae..0393f74d 100644 --- a/src/lib/ui/image.ts +++ b/src/lib/ui/image.ts @@ -1,2 +1,11 @@ -export const isImage = (url: string | undefined) => - /\.(jpeg|jpg|gif|png|svg|bmp|webp)$/i.test(url ?? '') +export const isImage = (url: string | undefined) => { + if (!url) return false + + return /\.(jpeg|jpg|gif|png|svg|bmp|webp)$/i.test(new URL(url).pathname) +} + +export const isVideo = (url: string | undefined) => { + if (!url) return false + + return new URL(url).pathname.toLowerCase().endsWith('.mp4') +} diff --git a/src/routes/c/[name]/+error.svelte b/src/routes/c/[name]/+error.svelte new file mode 100644 index 00000000..cd2590d9 --- /dev/null +++ b/src/routes/c/[name]/+error.svelte @@ -0,0 +1,7 @@ +
+ It's likely that this community hasn't been federated (nobody on your + instance has subscribed to it yet.) +
+