Add rich link previews for shared URLs

- Capture both URL and title when sharing links
- Create LinkPreviewView component with clickable cards
- Support markdown-style links [title](url)
- Auto-detect plain URLs in messages
- Add link metadata fetching on iOS
- Display clean preview cards with title, URL, and description
This commit is contained in:
jack
2025-07-08 04:32:57 +02:00
parent 244af2197c
commit b8d930614e
4 changed files with 225 additions and 16 deletions
@@ -111,9 +111,27 @@ class ShareViewController: SLComposeServiceViewController {
}
private func handleSharedURL(_ url: URL) {
// Convert URL to text and share
let text = url.absoluteString
saveToSharedDefaults(content: text, type: "url")
// Get the page title if available from the extension context
var pageTitle: String? = nil
if let item = extensionContext?.inputItems.first as? NSExtensionItem {
pageTitle = item.attributedContentText?.string ?? item.attributedTitle?.string
}
// Create a structured format for URL sharing
let urlData: [String: String] = [
"url": url.absoluteString,
"title": pageTitle ?? url.host ?? "Shared Link"
]
// Convert to JSON string
if let jsonData = try? JSONSerialization.data(withJSONObject: urlData),
let jsonString = String(data: jsonData, encoding: .utf8) {
saveToSharedDefaults(content: jsonString, type: "url")
} else {
// Fallback to simple URL
saveToSharedDefaults(content: url.absoluteString, type: "url")
}
openMainApp()
}