fix: Passing of start parameter to YouTube embed
This commit is contained in:
@@ -9,6 +9,12 @@ describe("YouTube", () => {
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
test("to be enabled on video link with timestamp", () => {
|
||||
expect(
|
||||
"https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=123s".match(match)
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
test("to be enabled on embed link", () => {
|
||||
expect(
|
||||
"https://www.youtube.com/embed?v=dQw4w9WgXcQ".match(match)
|
||||
|
||||
@@ -5,13 +5,21 @@ import { EmbedProps as Props } from ".";
|
||||
function YouTube(props: Props) {
|
||||
const { matches } = props.attrs;
|
||||
const videoId = matches[1];
|
||||
const queryParameters = matches[2];
|
||||
|
||||
let start;
|
||||
try {
|
||||
const url = new URL(props.attrs.href);
|
||||
const searchParams = new URLSearchParams(url.search);
|
||||
start = searchParams.get("t")?.replace(/s$/, "");
|
||||
} catch {
|
||||
// noop
|
||||
}
|
||||
|
||||
return (
|
||||
<Frame
|
||||
{...props}
|
||||
src={`https://www.youtube.com/embed/${videoId}?modestbranding=1${
|
||||
queryParameters ? `&${queryParameters}` : ""
|
||||
start ? `&start=${start}` : ""
|
||||
}`}
|
||||
title={`YouTube (${videoId})`}
|
||||
/>
|
||||
@@ -19,7 +27,7 @@ function YouTube(props: Props) {
|
||||
}
|
||||
|
||||
YouTube.ENABLED = [
|
||||
/(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?\/?.*(?:watch|embed)?(?:.*v=|v\/|\/)([a-zA-Z0-9_-]{11})(?:\?(.*))?$/i,
|
||||
/(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?\/?.*(?:watch|embed)?(?:.*v=|v\/|\/)([a-zA-Z0-9_-]{11})([\&\?](.*))?$/i,
|
||||
];
|
||||
|
||||
export default YouTube;
|
||||
|
||||
Reference in New Issue
Block a user