fix: youtube embeds not working
This commit is contained in:
1 parent
f5b380f005
commit
74701ffe3f
2 files changed
+21
-5
No files matched your search
@@ -35,14 +35,18 @@ export const optimizeImageURL = (
|
||||
try {
|
||||
const url = new URL(urlStr)
|
||||
url.searchParams.append('format', 'webp')
|
||||
url.searchParams.append('thumbnail', findClosestNumber([128, 256, 512, 1024], width).toString())
|
||||
url.searchParams.append(
|
||||
'thumbnail',
|
||||
findClosestNumber([128, 256, 512, 1024], width).toString()
|
||||
)
|
||||
return url.toString()
|
||||
} catch (e) {
|
||||
return urlStr
|
||||
}
|
||||
}
|
||||
|
||||
const YOUTUBE_REGEX = /^(?:(?:https?:)?\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/
|
||||
const YOUTUBE_REGEX =
|
||||
/^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|shorts\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/
|
||||
|
||||
export const isYoutubeLink = (url?: string): RegExpMatchArray | null => {
|
||||
if (!url) return null
|
||||
@@ -69,4 +73,4 @@ export const iframeType = (post: Post): IframeType => {
|
||||
if (isVideo(post.url)) return 'video'
|
||||
if (isYoutubeLink(post.url)) return 'youtube'
|
||||
return 'none'
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,18 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function youtubeVideoID(url: string): string | null {
|
||||
const regex =
|
||||
/^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|shorts\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/
|
||||
const match = url.match(regex)
|
||||
|
||||
if (match && match[1]) {
|
||||
return match[1]
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
@@ -36,8 +48,8 @@
|
||||
|
||||
if (type == 'youtube') {
|
||||
const url = new URL(inputUrl)
|
||||
const videoID = url.searchParams.get('v')
|
||||
url.searchParams.delete('v')
|
||||
|
||||
const videoID = youtubeVideoID(inputUrl)
|
||||
|
||||
return `https://${youtubeDomain(
|
||||
$userSettings.embeds.youtube
|
||||
|
||||
Reference in new issue
Block a user