From 417d531e53d5bc93463b7520f33642d4765c9e21 Mon Sep 17 00:00:00 2001 From: Renard Date: Tue, 17 Sep 2019 16:10:26 -0300 Subject: Embed youtube videos --- src/Post.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/Post.js') diff --git a/src/Post.js b/src/Post.js index db46106..be831a1 100644 --- a/src/Post.js +++ b/src/Post.js @@ -1,5 +1,13 @@ import React from "react"; -import { Image, Icon, Modal, Comment, Flag } from "semantic-ui-react"; +import { + Image, + Icon, + Modal, + Comment, + Flag, + Embed, + Label +} from "semantic-ui-react"; import Moment from "react-moment"; import "moment/locale/es"; import { avatars } from "./Quotes"; @@ -71,6 +79,11 @@ const Post = ({ index, post, locked, threadId, currentBoard }) => { if (post.tripcode === " (★ ****-****)") { post.tripcode = ""; } + //(?:https?:\/\/)?(?:www\.)?youtu(.be\/|be\.com\/watch\?v=)(\w{11}) + const youtubeRe = RegExp( + /(?:https?:\/\/)?(?:www\.)?youtu(.be\/|be\.com\/watch\?v=)(\w{11})/g + ); + const youtubeVideos = post.message.match(youtubeRe); return ( @@ -122,6 +135,23 @@ const Post = ({ index, post, locked, threadId, currentBoard }) => { {filesize(post.file_size, { bits: true })} ) : null} + + {youtubeVideos !== null + ? youtubeVideos.map((url, i) => { + let id = url.split("?v=")[1]; + return ( +
+ +
+ ); + }) + : null} +