feat(post): show embed of link in post content even if it doesn't have a thumbnail

This commit is contained in:
Tom (plebeius.eth)
2024-08-31 14:22:02 +02:00
parent 2ccec85e56
commit 09a14416c8
+12 -8
View File
@@ -11,6 +11,7 @@ import useIsMobile from '../../hooks/use-is-mobile';
import CommentMedia from '../comment-media'; import CommentMedia from '../comment-media';
import styles from './markdown.module.css'; import styles from './markdown.module.css';
import { useLocation, useParams } from 'react-router-dom'; import { useLocation, useParams } from 'react-router-dom';
import { canEmbed } from '../embed';
interface ContentLinkEmbedProps { interface ContentLinkEmbedProps {
children: any; children: any;
@@ -86,13 +87,15 @@ const ContentLinkEmbed = ({ children, href, linkMediaInfo }: ContentLinkEmbedPro
<CommentMedia isReply={false} setShowThumbnail={setShowMedia} commentMediaInfo={linkMediaInfo} showThumbnail={false} /> <CommentMedia isReply={false} setShowThumbnail={setShowMedia} commentMediaInfo={linkMediaInfo} showThumbnail={false} />
</> </>
)} )}
<FloatingPortal> {getHasThumbnail(linkMediaInfo, href) && (
{isOpen && !isMobile && ( <FloatingPortal>
<div className={styles.floatingEmbed} ref={refs.setFloating} style={floatingStyles} {...getFloatingProps()}> {isOpen && !isMobile && (
<CommentMedia isReply={false} isFloatingEmbed={true} setShowThumbnail={setShowMedia} commentMediaInfo={linkMediaInfo} showThumbnail={true} /> <div className={styles.floatingEmbed} ref={refs.setFloating} style={floatingStyles} {...getFloatingProps()}>
</div> <CommentMedia isReply={false} isFloatingEmbed={true} setShowThumbnail={setShowMedia} commentMediaInfo={linkMediaInfo} showThumbnail={true} />
)} </div>
</FloatingPortal> )}
</FloatingPortal>
)}
</> </>
); );
}; };
@@ -172,7 +175,8 @@ const Markdown = ({ content, title }: MarkdownProps) => {
a: ({ href, children }) => { a: ({ href, children }) => {
if (href && !isInCatalogView) { if (href && !isInCatalogView) {
const linkMediaInfo = getLinkMediaInfo(href); const linkMediaInfo = getLinkMediaInfo(href);
if (getHasThumbnail(linkMediaInfo, href)) { const embedUrl = new URL(href);
if (canEmbed(embedUrl) || getHasThumbnail(linkMediaInfo, href)) {
return <ContentLinkEmbed children={children} href={href} linkMediaInfo={linkMediaInfo} />; return <ContentLinkEmbed children={children} href={href} linkMediaInfo={linkMediaInfo} />;
} else { } else {
return ( return (