diff options
| author | MaheshtheDev <[email protected]> | 2026-01-22 02:35:35 +0000 |
|---|---|---|
| committer | MaheshtheDev <[email protected]> | 2026-01-22 02:35:35 +0000 |
| commit | 7972e543c47cb97b1716bbfe305d3244eb4d00bf (patch) | |
| tree | 6968ac91eb4161d33bac4042dbba3958c78482a5 /apps/web/lib | |
| parent | Re - feat(pipecat-sdk): add speech-to-speech model support (Gemini Live) (#683) (diff) | |
| download | supermemory-7972e543c47cb97b1716bbfe305d3244eb4d00bf.tar.xz supermemory-7972e543c47cb97b1716bbfe305d3244eb4d00bf.zip | |
chore: cmdk, google docs viewer, image preview, document icons (#691)01-21-chore_cmdk_google_docs_viewer_image_preview_document_icons
Diffstat (limited to 'apps/web/lib')
| -rw-r--r-- | apps/web/lib/url-helpers.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/apps/web/lib/url-helpers.ts b/apps/web/lib/url-helpers.ts index e4147a05..d171a6c2 100644 --- a/apps/web/lib/url-helpers.ts +++ b/apps/web/lib/url-helpers.ts @@ -188,3 +188,49 @@ export function toLinkedInProfileUrl(handle: string): string { if (!handle.trim()) return "" return `https://linkedin.com/in/${handle.trim()}` } + +/** + * Gets the favicon URL for a given URL. + */ +export function getFaviconUrl(url: string | null | undefined): string | null { + if (!url) return null + try { + const urlObj = new URL(url) + return `https://www.google.com/s2/favicons?domain=${urlObj.hostname}&sz=16` + } catch { + return null + } +} + +/** + * Extracts the document ID from a Google Docs/Sheets/Slides URL. + * Works with various URL formats: + * - https://docs.google.com/document/d/{id}/edit + * - https://docs.google.com/spreadsheets/d/{id}/edit#gid=0 + * - https://docs.google.com/presentation/d/{id}/edit + */ +export function extractGoogleDocId(url: string): string | null { + try { + const match = url.match(/\/d\/([a-zA-Z0-9_-]+)/) + return match?.[1] ?? null + } catch { + return null + } +} + +/** + * Generates the embed URL for a Google document based on its type. + */ +export function getGoogleEmbedUrl( + docId: string, + type: "google_doc" | "google_sheet" | "google_slide", +): string { + switch (type) { + case "google_doc": + return `https://docs.google.com/document/d/${docId}/preview` + case "google_sheet": + return `https://docs.google.com/spreadsheets/d/${docId}/preview` + case "google_slide": + return `https://docs.google.com/presentation/d/${docId}/embed?start=false&loop=false&delayms=3000` + } +} |