From c68e5099797d5b49ed6441ce04d7c77105327f73 Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Sun, 3 Aug 2025 23:35:06 -0700
Subject: feat(web): Add special cards for specific websites. Fixes #1344

---
 .../preview/content-renderers/XRenderer.tsx        | 58 ++++++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100644 apps/web/components/dashboard/preview/content-renderers/XRenderer.tsx

(limited to 'apps/web/components/dashboard/preview/content-renderers/XRenderer.tsx')

diff --git a/apps/web/components/dashboard/preview/content-renderers/XRenderer.tsx b/apps/web/components/dashboard/preview/content-renderers/XRenderer.tsx
new file mode 100644
index 00000000..e3e43843
--- /dev/null
+++ b/apps/web/components/dashboard/preview/content-renderers/XRenderer.tsx
@@ -0,0 +1,58 @@
+import { MessageSquare } from "lucide-react";
+import { Tweet } from "react-tweet";
+
+import { BookmarkTypes, ZBookmark } from "@karakeep/shared/types/bookmarks";
+
+import { ContentRenderer } from "./types";
+
+function extractTweetId(url: string): string | null {
+  const patterns = [
+    /(?:twitter\.com|x\.com)\/\w+\/status\/(\d+)/,
+    /(?:twitter\.com|x\.com)\/i\/web\/status\/(\d+)/,
+  ];
+
+  for (const pattern of patterns) {
+    const match = url.match(pattern);
+    if (match) {
+      return match[1];
+    }
+  }
+  return null;
+}
+
+function canRenderX(bookmark: ZBookmark): boolean {
+  if (bookmark.content.type !== BookmarkTypes.LINK) {
+    return false;
+  }
+
+  const url = bookmark.content.url;
+  return extractTweetId(url) !== null;
+}
+
+function XRendererComponent({ bookmark }: { bookmark: ZBookmark }) {
+  if (bookmark.content.type !== BookmarkTypes.LINK) {
+    return null;
+  }
+
+  const tweetId = extractTweetId(bookmark.content.url);
+  if (!tweetId) {
+    return null;
+  }
+
+  return (
+    <div className="relative h-full w-full overflow-auto">
+      <div className="flex justify-center p-4">
+        <Tweet id={tweetId} />
+      </div>
+    </div>
+  );
+}
+
+export const xRenderer: ContentRenderer = {
+  id: "x",
+  name: "X (Twitter)",
+  icon: MessageSquare,
+  canRender: canRenderX,
+  component: XRendererComponent,
+  priority: 10,
+};
-- 
cgit v1.2.3-70-g09d2

