feat: add youtube video embeds
This commit is contained in:
1 parent
00840227d2
commit
eeca5a826a
7 files changed
+133
-8
No files matched your search
@@ -1,4 +1,6 @@
|
||||
import { getInstance } from '$lib/lemmy.js'
|
||||
import type { View } from '$lib/settings'
|
||||
import { isImage, isVideo } from '$lib/ui/image'
|
||||
import type { CommentView, PersonView, Post, PostView } from 'lemmy-js-client'
|
||||
|
||||
export const isCommentMutable = (comment: CommentView, me: PersonView) =>
|
||||
@@ -25,4 +27,26 @@ export const bestImageURL = (
|
||||
return post.url ?? ''
|
||||
}
|
||||
|
||||
const YOUTUBE_REGEX = /^(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(\w|-){11}$/
|
||||
|
||||
export const isYoutubeLink = (url?: string): boolean => {
|
||||
if (!url) return false
|
||||
|
||||
return YOUTUBE_REGEX.test(url)
|
||||
}
|
||||
|
||||
export const postLink = (post: Post) => `/post/${getInstance()}/${post.id}`
|
||||
|
||||
export type MediaType = 'video' | 'image' | 'iframe' | 'embed' | 'none'
|
||||
export type IframeType = 'youtube'
|
||||
|
||||
export const mediaType = (post: Post, view: View = 'cozy'): MediaType => {
|
||||
if (post.url) {
|
||||
if (isImage(post.url)) return 'image'
|
||||
if (isVideo(post.url)) return 'video'
|
||||
if (isYoutubeLink(post.url)) return 'iframe'
|
||||
return 'embed'
|
||||
}
|
||||
|
||||
return 'none'
|
||||
}
|
||||
Reference in new issue
Block a user