fix: show videos in iframes, close #222
This commit is contained in:
1 parent
d75fcb328f
commit
0557b520ef
4 files changed
+40
-17
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "photon-lemmy",
|
"name": "photon-lemmy",
|
||||||
"version": "1.24.0",
|
"version": "1.24.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
|||||||
@@ -27,26 +27,31 @@ export const bestImageURL = (
|
|||||||
return post.url ?? ''
|
return post.url ?? ''
|
||||||
}
|
}
|
||||||
|
|
||||||
const YOUTUBE_REGEX = /^(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(\w|-){11}$/
|
const YOUTUBE_REGEX = /^(?:(?:https?:)?\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/
|
||||||
|
|
||||||
export const isYoutubeLink = (url?: string): boolean => {
|
export const isYoutubeLink = (url?: string): RegExpMatchArray | null => {
|
||||||
if (!url) return false
|
if (!url) return null
|
||||||
|
|
||||||
return YOUTUBE_REGEX.test(url)
|
return url.match(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const postLink = (post: Post) => `/post/${getInstance()}/${post.id}`
|
export const postLink = (post: Post) => `/post/${getInstance()}/${post.id}`
|
||||||
|
|
||||||
export type MediaType = 'video' | 'image' | 'iframe' | 'embed' | 'none'
|
export type MediaType = 'video' | 'image' | 'iframe' | 'embed' | 'none'
|
||||||
export type IframeType = 'youtube' | 'none'
|
export type IframeType = 'youtube' | 'video' | 'none'
|
||||||
|
|
||||||
export const mediaType = (post: Post, view: View = 'cozy'): MediaType => {
|
export const mediaType = (post: Post, view: View = 'cozy'): MediaType => {
|
||||||
if (post.url) {
|
if (post.url) {
|
||||||
if (isImage(post.url)) return 'image'
|
if (isImage(post.url)) return 'image'
|
||||||
if (isVideo(post.url)) return 'video'
|
if (isVideo(post.url)) return 'iframe'
|
||||||
if (isYoutubeLink(post.url)) return 'iframe'
|
if (isYoutubeLink(post.url)) return 'iframe'
|
||||||
return 'embed'
|
return 'embed'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 'none'
|
||||||
|
}
|
||||||
|
export const iframeType = (post: Post): IframeType => {
|
||||||
|
if (isVideo(post.url)) return 'video'
|
||||||
|
if (isYoutubeLink(post.url)) return 'youtube'
|
||||||
return 'none'
|
return 'none'
|
||||||
}
|
}
|
||||||
@@ -30,6 +30,10 @@
|
|||||||
export let opened = !$userSettings.embeds.clickToView
|
export let opened = !$userSettings.embeds.clickToView
|
||||||
|
|
||||||
const urlToEmbed = (inputUrl: string) => {
|
const urlToEmbed = (inputUrl: string) => {
|
||||||
|
if (type == 'video') {
|
||||||
|
return inputUrl
|
||||||
|
}
|
||||||
|
|
||||||
if (type == 'youtube') {
|
if (type == 'youtube') {
|
||||||
const url = new URL(inputUrl)
|
const url = new URL(inputUrl)
|
||||||
const videoID = url.searchParams.get('v')
|
const videoID = url.searchParams.get('v')
|
||||||
@@ -56,6 +60,12 @@
|
|||||||
text: 'YouTube Video',
|
text: 'YouTube Video',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case 'video': {
|
||||||
|
return {
|
||||||
|
icon: VideoCamera,
|
||||||
|
text: 'Video',
|
||||||
|
}
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
return {
|
return {
|
||||||
icon: PuzzlePiece,
|
icon: PuzzlePiece,
|
||||||
@@ -70,18 +80,25 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if opened}
|
{#if opened}
|
||||||
<iframe
|
{#if type == 'video'}
|
||||||
src={embedUrl}
|
<!-- svelte-ignore a11y-media-has-caption -->
|
||||||
title="Embed player"
|
<video controls class="rounded-xl aspect-video">
|
||||||
frameborder="0"
|
<source src={url} />
|
||||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
</video>
|
||||||
allowfullscreen
|
{:else}
|
||||||
class="aspect-video rounded-xl dark:bg-zinc-900"
|
<iframe
|
||||||
/>
|
src={embedUrl}
|
||||||
|
title="Embed player"
|
||||||
|
frameborder="0"
|
||||||
|
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
||||||
|
allowfullscreen
|
||||||
|
class="aspect-video rounded-xl dark:bg-zinc-900"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
{:else}
|
{:else}
|
||||||
<button
|
<button
|
||||||
on:click={() => (opened = true)}
|
on:click={() => (opened = true)}
|
||||||
class="aspect-video w-full h-full z-0 overflow-hidden relative rounded-xl flex flex-col gap-2 items-center justify-center"
|
class="aspect-video w-full h-full z-0 overflow-hidden relative rounded-xl flex flex-col gap-2 items-center justify-center text-white"
|
||||||
>
|
>
|
||||||
{#if thumbnail}
|
{#if thumbnail}
|
||||||
<img
|
<img
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
bestImageURL,
|
bestImageURL,
|
||||||
postLink,
|
postLink,
|
||||||
type MediaType,
|
type MediaType,
|
||||||
|
iframeType,
|
||||||
} from '$lib/components/lemmy/post/helpers.js'
|
} from '$lib/components/lemmy/post/helpers.js'
|
||||||
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte'
|
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte'
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { userSettings } from '$lib/settings.js'
|
||||||
@@ -95,7 +96,7 @@
|
|||||||
{:else if type == 'iframe' && (view == 'cozy' || view == 'card') && post.url}
|
{:else if type == 'iframe' && (view == 'cozy' || view == 'card') && post.url}
|
||||||
<PostIframe
|
<PostIframe
|
||||||
thumbnail={post.thumbnail_url}
|
thumbnail={post.thumbnail_url}
|
||||||
type="youtube"
|
type={iframeType(post)}
|
||||||
url={post.url}
|
url={post.url}
|
||||||
{opened}
|
{opened}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in new issue
Block a user