mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
fixed youtube thumbs
This commit is contained in:
parent
aaa8eb5275
commit
45f7c70f83
3 changed files with 13 additions and 20 deletions
|
@ -1,7 +1,7 @@
|
|||
import React, { FC, memo, useMemo } from 'react';
|
||||
import { ICommentBlock } from '~/constants/comment';
|
||||
import styles from './styles.scss';
|
||||
import { getYoutubeTitle } from '~/utils/dom';
|
||||
import { getYoutubeTitle, getYoutubeThumb } from '~/utils/dom';
|
||||
import { Icon } from '~/components/input/Icon';
|
||||
|
||||
interface IProps {
|
||||
|
@ -13,15 +13,7 @@ const CommentEmbedBlock: FC<IProps> = memo(({ block }) => {
|
|||
/(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]);
|
||||
const preview = useMemo(() => getYoutubeThumb(block.content), [block.content]);
|
||||
|
||||
return (
|
||||
<div className={styles.embed}>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue