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
+5 -1
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,6 +87,7 @@ const ContentLinkEmbed = ({ children, href, linkMediaInfo }: ContentLinkEmbedPro
<CommentMedia isReply={false} setShowThumbnail={setShowMedia} commentMediaInfo={linkMediaInfo} showThumbnail={false} /> <CommentMedia isReply={false} setShowThumbnail={setShowMedia} commentMediaInfo={linkMediaInfo} showThumbnail={false} />
</> </>
)} )}
{getHasThumbnail(linkMediaInfo, href) && (
<FloatingPortal> <FloatingPortal>
{isOpen && !isMobile && ( {isOpen && !isMobile && (
<div className={styles.floatingEmbed} ref={refs.setFloating} style={floatingStyles} {...getFloatingProps()}> <div className={styles.floatingEmbed} ref={refs.setFloating} style={floatingStyles} {...getFloatingProps()}>
@@ -93,6 +95,7 @@ const ContentLinkEmbed = ({ children, href, linkMediaInfo }: ContentLinkEmbedPro
</div> </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 (