From 5f674d4691073da0bca879f681311b4f35c41c48 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Tue, 4 Jul 2023 20:18:25 -0700 Subject: [PATCH] feat: Add communities --- src/lib/components/lemmy/Post.svelte | 9 ++++++++- src/lib/ui/image.ts | 13 +++++++++++-- src/routes/c/[name]/+error.svelte | 7 +++++++ src/routes/post/[instance]/[id]/+page.svelte | 7 ++++++- 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 src/routes/c/[name]/+error.svelte 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 @@ +

+

404

+

+ It's likely that this community hasn't been federated (nobody on your + instance has subscribed to it yet.) +

+
diff --git a/src/routes/post/[instance]/[id]/+page.svelte b/src/routes/post/[instance]/[id]/+page.svelte index c8cae14e..904ae57f 100644 --- a/src/routes/post/[instance]/[id]/+page.svelte +++ b/src/routes/post/[instance]/[id]/+page.svelte @@ -5,7 +5,7 @@ import Comments from '$lib/components/lemmy/comment/Comments.svelte' import SvelteMarkdown from 'svelte-markdown' import CommunityLink from '$lib/components/community/CommunityLink.svelte' - import { isImage } from '$lib/ui/image.js' + import { isImage, isVideo } from '$lib/ui/image.js' import { user } from '$lib/lemmy.js' import CommentForm from '$lib/components/lemmy/comment/CommentForm.svelte' import PostVote from '$lib/components/lemmy/PostVote.svelte' @@ -107,6 +107,11 @@ alt={post.name} class="rounded-md max-w-screen max-h-[80vh] mx-auto" /> + {:else if isVideo(post.url)} + + {/if} {#if post.body}