mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-07 09:25:29 +08:00
feat(youtube): enhance embed URL generation to support video lists (#6096)
* feat(youtube): enhance embed URL generation to support video lists * chore: add changeset * feat(youtube): update embed URL generation to support playlists
This commit is contained in:
parent
81009d2160
commit
151de93d05
5
.changeset/shiny-goats-poke.md
Normal file
5
.changeset/shiny-goats-poke.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@tiptap/extension-youtube": minor
|
||||
---
|
||||
|
||||
feat(youtube): enhance embed URL generation to support video lists
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user