Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only match links with inner text as "iframe" #83

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions src/app/(routes)/blog/[slug]/_components/article-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const markRenderers: RenderMark = {

function createMaybeYoutubeEmbedLink(url: URL) {
if (!url.hostname.includes("youtube.com")) return;

if (url.pathname.includes("embed")) {
// already an embed link
return url.href;
Expand All @@ -44,37 +43,38 @@ const nodeRenderers: RenderNode = {
[INLINES.HYPERLINK]: (node, children) => {
const url = new URL(node.data.uri as string);

const href = generateEmbedHref(url);

if (
url.hostname.includes("youtube.com") ||
url.hostname.includes("player.vimeo.com") ||
children?.toString().toLowerCase().includes("iframe") // to handle uncommon cases, creator can set the text to "iframe"
) {
return (
<IframeContainer>
<iframe
width="100%"
height="100%"
src={href}
title="YouTube video player"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowFullScreen
style={{
position: "absolute",
top: 0,
left: 0,
clipPath: "inset(0% 0% 0% 0% round 16px)",
}}
></iframe>
</IframeContainer>
);
if (children?.toString().toLowerCase().includes("iframe")) {
if (
url.hostname.includes("youtube.com") ||
url.hostname.includes("player.vimeo.com")
) {
const href = generateEmbedHref(url);
return (
<IframeContainer>
<iframe
width="100%"
height="100%"
src={href}
title="YouTube video player"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowFullScreen
style={{
position: "absolute",
top: 0,
left: 0,
clipPath: "inset(0% 0% 0% 0% round 16px)",
}}
></iframe>
</IframeContainer>
);
}
}

return (
<Link
target={isExternal(href) ? "_blank" : undefined}
target={isExternal(url.href) ? "_blank" : undefined}
className="hover:text-text underline"
href={href}
href={url.href}
type="external"
>
{children}
Expand Down
Loading