import { Component, JSX, Switch, Match, createSignal, createEffect, Show } from 'solid-js'; import LazyLoad from '@/components/utils/LazyLoad'; import SafeLink from '@/components/utils/SafeLink'; import useConfig from '@/core/useConfig'; import { useTranslation } from '@/i18n/useTranslation'; import { useOgp, isOgpUrl } from '@/utils/ogp'; import { isTwitterUrl, parseYouTubeVideoUrl } from '@/utils/url'; type PreviewedLinkProps = { url: string; initialHidden: boolean; children?: JSX.Element; }; const twitterUrl = (urlString: string): string => { try { const url = new URL(urlString); url.host = 'twitter.com'; return url.href; } catch { return urlString; } }; const youtubeUrl = (videoId: string): string => { const iframeUrl = new URL(`https://www.youtube-nocookie.com/embed/`); iframeUrl.pathname += videoId; iframeUrl.searchParams.set('origin', window.location.origin); return iframeUrl.href; }; const TwitterEmbed: Component<{ url: string }> = (props) => { let twitterRef: HTMLQuoteElement | undefined; const { getColorTheme } = useConfig(); createEffect(() => { if (isTwitterUrl(props.url)) { window.twttr?.widgets?.load(twitterRef); } }); const dataTheme = () => { const colorTheme = getColorTheme(); if (colorTheme.brightness === 'dark') { return 'dark'; } return 'light'; }; return (
{twitterUrl(props.url)}); }; const OgpEmbed: Component<{ class?: string; url: string }> = (props) => { const { ogp } = useOgp(() => ({ url: props.url, })); return (