Skip to content
Source
Sign inSign up
pingdotgg/t3code

refactor(web): chat markdown links and file chips live in their own modules #22693

Mergedjuliusmarmingemerged 1 commit intorefactor/chat-markdown-tables fromrefs/pull/22693/headmerged by juliusmarminge View on GitHub

Showing 6 changed files with 172 additions and 0 deletions (loading 4).

x
0 of 6 viewed, 6 left
110 additions and 0 deletionsapps/web/src/components/chat/MarkdownExternalLink.tsxAdded
View file
@@ -0,0 +1,110 @@
+import { faviconUrlForOrigin } from "@t3tools/shared/favicon";
+import { GlobeIcon } from "lucide-react";
+import { Children, Fragment, memo, useState, type ReactNode } from "react";
+​
+import { cn } from "../../lib/utils";
+import { GitHubIcon } from "../Icons";
+​
+const MARKDOWN_LINK_FAVICON_CLASS_NAME = "block size-full shrink-0 select-none";
+​
+const failedFaviconHosts = new Set<string>();
+​
+function isGitHubHost(host: string): boolean {
+ const hostname = host.toLowerCase();
+ return hostname === "github.com" || hostname.endsWith(".github.com");
+}
+​
+const MarkdownLinkFavicon = memo(function MarkdownLinkFavicon({ host }: { host: string }) {
+ const [failedHost, setFailedHost] = useState<string | null>(null);
+ const brandIcon = isGitHubHost(host);
+ const faviconUrl = brandIcon ? null : faviconUrlForOrigin(`https://${host}`);
+ return (
+ <span
+ className="ms-[0.25em] me-[0.2em] inline-flex size-[14px] [vertical-align:-0.125em]"
+ aria-hidden
+ >
+ {brandIcon ? (
+ <GitHubIcon className={MARKDOWN_LINK_FAVICON_CLASS_NAME} />
+ ) : faviconUrl === null || failedHost === host || failedFaviconHosts.has(host) ? (
+ <GlobeIcon className={MARKDOWN_LINK_FAVICON_CLASS_NAME} />
+ ) : (