[site/components][s]: add start time support for youtube embeds
This commit is contained in:
parent
5182148867
commit
03041ec503
|
|
@ -1,6 +1,6 @@
|
||||||
import LiteYouTubeEmbed from "react-lite-youtube-embed";
|
import LiteYouTubeEmbed from "react-lite-youtube-embed";
|
||||||
import TwitterEmbed from "./TwitterEmbed";
|
import TwitterEmbed from "./TwitterEmbed";
|
||||||
import { YOUTUBE_REGEX, TWITTER_REGEX } from "../lib/constants";
|
import { YOUTUBE_REGEX, TWITTER_REGEX, YOUTUBE_ID_REGEX } from "../lib/constants";
|
||||||
|
|
||||||
export const Paragraph = (props) => {
|
export const Paragraph = (props) => {
|
||||||
if (
|
if (
|
||||||
|
|
@ -8,13 +8,17 @@ export const Paragraph = (props) => {
|
||||||
props.children.props &&
|
props.children.props &&
|
||||||
props.children.props.href
|
props.children.props.href
|
||||||
) {
|
) {
|
||||||
if (YOUTUBE_REGEX.test(props.children.props.href)) {
|
const href = props.children.props.href
|
||||||
const youtubeId = props.children.props.href.split(/^|=|\//).pop();
|
|
||||||
return <LiteYouTubeEmbed id={youtubeId} />;
|
if (YOUTUBE_REGEX.test(href)) {
|
||||||
|
const youtubeId = href.match(YOUTUBE_ID_REGEX)[1];
|
||||||
|
let startTime = href.match(/t=[0-9]*/)
|
||||||
|
if (startTime) startTime = startTime[0].split("=").pop()
|
||||||
|
return <LiteYouTubeEmbed id={youtubeId} params={`start=${startTime}`} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TWITTER_REGEX.test(props.children.props.href)) {
|
if (TWITTER_REGEX.test(href)) {
|
||||||
return <TwitterEmbed url={props.children.props.href} {...props} />;
|
return <TwitterEmbed url={href} {...props} />;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return <p {...props} />;
|
return <p {...props} />;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue