diff --git a/src/components/comment/CommentEmbedBlock/index.tsx b/src/components/comment/CommentEmbedBlock/index.tsx index b96996e4..b2744889 100644 --- a/src/components/comment/CommentEmbedBlock/index.tsx +++ b/src/components/comment/CommentEmbedBlock/index.tsx @@ -1,6 +1,8 @@ -import React, { FC, memo } from 'react'; +import React, { FC, memo, useMemo } from 'react'; import { ICommentBlock } from '~/constants/comment'; import styles from './styles.scss'; +import { getYoutubeTitle } from '~/utils/dom'; +import { Icon } from '~/components/input/Icon'; interface IProps { block: ICommentBlock; @@ -8,14 +10,28 @@ interface IProps { const CommentEmbedBlock: FC = memo(({ block }) => { const link = block.content.match( - /(https?:\/\/(www\.)?(youtube\.com|youtu\.be)\/(watch)?(\?v=)?[\w\-]+)/gi + /(https?:\/\/(www\.)?(youtube\.com|youtu\.be)\/(watch)?(\?v=)?[\w\-\&\=]+)/gi ); + const preview = useMemo(() => { + const match = + block.content && + block.content.match( + /http(?:s?):\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-\_]*)(&(amp;)?[\w\?=]*)?/ + ); + + return match && match[1] ? `http://img.youtube.com/vi/${match[1]}/maxresdefault.jpg` : null; + }, [block.content]); + return ( -
- - {link[0]} - +
+ + +
+
+
{link[0]}
+
+
); }); diff --git a/src/components/comment/CommentEmbedBlock/styles.scss b/src/components/comment/CommentEmbedBlock/styles.scss index 229f3cfe..60a84f91 100644 --- a/src/components/comment/CommentEmbedBlock/styles.scss +++ b/src/components/comment/CommentEmbedBlock/styles.scss @@ -1,3 +1,66 @@ -.text { +.embed { padding: 0 $gap; + height: $comment_height; + width: 100%; + box-sizing: border-box; + background: 50% 50% no-repeat/cover; + position: relative; + display: flex; + align-items: center; + justify-content: flex-start; + margin: 0 0 $gap 0; + + a { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + z-index: 7; + } + + svg { + fill: white; + position: relative; + z-index: 6; + } +} + +.backdrop { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: transparentize(black, 0.5); + z-index: 15; + border-radius: $radius; + display: flex; + align-items: center; + justify-content: center; + + @include can_backdrop { + background: transparentize(black, 0.3); + backdrop-filter: blur(5px); + } +} + +.preview { + padding: 0 $gap $gap / 2; + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + display: flex; + align-items: stretch; + justify-content: stretch; + box-sizing: border-box; + z-index: 2; + + & > div { + width: 100%; + border-radius: $radius; + position: relative; + } } diff --git a/src/constants/comment.ts b/src/constants/comment.ts index a89e3e4c..916f18a2 100644 --- a/src/constants/comment.ts +++ b/src/constants/comment.ts @@ -10,7 +10,7 @@ export const COMMENT_BLOCK_TYPES = { export const COMMENT_BLOCK_DETECTORS = [ { type: COMMENT_BLOCK_TYPES.EMBED, - test: /(https?:\/\/(www\.)?(youtube\.com|youtu\.be)\/(watch)?(\?v=)?[\w\-]+)/gim, + test: /(https?:\/\/(www\.)?(youtube\.com|youtu\.be)\/(watch)?(\?v=)?[\w\-\&\=]+)/gim, }, { type: COMMENT_BLOCK_TYPES.MARK, diff --git a/src/sprites/Sprites.tsx b/src/sprites/Sprites.tsx index 0efcf940..97fe173b 100644 --- a/src/sprites/Sprites.tsx +++ b/src/sprites/Sprites.tsx @@ -1,4 +1,4 @@ -import React, { FC } from "react"; +import React, { FC } from 'react'; const Sprites: FC<{}> = () => ( @@ -191,6 +191,13 @@ const Sprites: FC<{}> = () => ( + + + + + + + ); diff --git a/src/utils/dom.ts b/src/utils/dom.ts index 0e0a21e0..b13ed3f1 100644 --- a/src/utils/dom.ts +++ b/src/utils/dom.ts @@ -78,7 +78,7 @@ export const formatText = (text: string): string => ? '' : text .replace( - /(https?:\/\/(www\.)?(youtube\.com|youtu\.be)\/(watch)?(\?v=)?[\w\-]+)/gim, + /(https?:\/\/(www\.)?(youtube\.com|youtu\.be)\/(watch)?(\?v=)?[\w\-\&\=]+)/gim, '\n$1\n' ) .replace(/\n{1,}/gim, '\n')