Merge branch 'develop' of github.com:ueberdosis/tiptap

This commit is contained in:
Dominik Biedebach 2025-03-28 12:49:47 +01:00
commit 2bf703e0a0
2 changed files with 13 additions and 5 deletions

View File

@ -0,0 +1,5 @@
---
"@tiptap/extension-youtube": minor
---
feat(youtube): enhance embed URL generation to support video lists

View File

@ -27,7 +27,10 @@ export interface GetEmbedUrlOptions {
rel?: number;
}
export const getYoutubeEmbedUrl = (nocookie?: boolean) => {
export const getYoutubeEmbedUrl = (nocookie?: boolean, isPlaylist?:boolean) => {
if (isPlaylist) {
return 'https://www.youtube-nocookie.com/embed/videoseries?list='
}
return nocookie ? 'https://www.youtube-nocookie.com/embed/' : 'https://www.youtube.com/embed/'
}
@ -73,14 +76,14 @@ export const getEmbedUrlFromYoutubeUrl = (options: GetEmbedUrlOptions) => {
return `${getYoutubeEmbedUrl(nocookie)}${id}`
}
const videoIdRegex = /(?:v=|shorts\/)([-\w]+)/gm
const videoIdRegex = /(?:(v|list)=|shorts\/)([-\w]+)/gm
const matches = videoIdRegex.exec(url)
if (!matches || !matches[1]) {
if (!matches || !matches[2]) {
return null
}
let outputUrl = `${getYoutubeEmbedUrl(nocookie)}${matches[1]}`
let outputUrl = `${getYoutubeEmbedUrl(nocookie, matches[1] === 'list')}${matches[2]}`
const params = []
@ -153,7 +156,7 @@ export const getEmbedUrlFromYoutubeUrl = (options: GetEmbedUrlOptions) => {
}
if (params.length) {
outputUrl += `?${params.join('&')}`
outputUrl += `${matches[1] === 'v' ? '?' : '&'}${params.join('&')}`
}
return outputUrl