Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to set rel on youtube embed link #6083

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thirty-forks-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tiptap/extension-youtube": major
---

This change adds option to set rel parameter on youtube embed link
6 changes: 6 additions & 0 deletions packages/extension-youtube/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface GetEmbedUrlOptions {
playlist?: string;
progressBarColor?: string;
startAt?: number;
rel?: number;
}

export const getYoutubeEmbedUrl = (nocookie?: boolean) => {
Expand All @@ -50,6 +51,7 @@ export const getEmbedUrlFromYoutubeUrl = (options: GetEmbedUrlOptions) => {
playlist,
progressBarColor,
startAt,
rel,
} = options

if (!isValidYoutubeUrl(url)) {
Expand Down Expand Up @@ -146,6 +148,10 @@ export const getEmbedUrlFromYoutubeUrl = (options: GetEmbedUrlOptions) => {
params.push(`color=${progressBarColor}`)
}

if(rel !== undefined) {
params.push(`rel=${rel}`)
}

if (params.length) {
outputUrl += `?${params.join('&')}`
}
Expand Down
10 changes: 10 additions & 0 deletions packages/extension-youtube/src/youtube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ export interface YoutubeOptions {
* @example 1280
*/
width: number;

/**
* Controls if the related youtube videos at the end are from the same channel.
* @default 1
* @example 0
*/
rel: number;
}

/**
Expand Down Expand Up @@ -199,6 +206,7 @@ export const Youtube = Node.create<YoutubeOptions>({
playlist: '',
progressBarColor: undefined,
width: 640,
rel: 1,
}
},

Expand Down Expand Up @@ -288,6 +296,7 @@ export const Youtube = Node.create<YoutubeOptions>({
playlist: this.options.playlist,
progressBarColor: this.options.progressBarColor,
startAt: HTMLAttributes.start || 0,
rel: this.options.rel,
})

HTMLAttributes.src = embedUrl
Expand Down Expand Up @@ -316,6 +325,7 @@ export const Youtube = Node.create<YoutubeOptions>({
origin: this.options.origin,
playlist: this.options.playlist,
progressBarColor: this.options.progressBarColor,
rel: this.options.rel,
},
HTMLAttributes,
),
Expand Down