- DeepLinkRouter als pure-Logic-Enum aus RootView extrahiert (resolveToWebURL, isExplorePath, route) - 11 DeepLinkRouterTests grün: custom-scheme, https passthrough, Erkunden-vs-Lesen-Routing, Substring-Guard - WebShellScripts.hideWebHeader: WKUserScript injiziert at document.start CSS, das den zitare-Web-Header (body header:has(a.brand)) ausblendet. Native TabBar übernimmt globale Navigation, Content bleibt sichtbar. - Simulator-Verifikation: Quote rendert ohne doppelte Nav-Leiste, 17 (UI + Unit) Tests grün Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
38 lines
1.6 KiB
Swift
38 lines
1.6 KiB
Swift
import Foundation
|
|
|
|
/// Routet sowohl Custom-Scheme- (`zitare://`) als auch Universal-Link-URLs
|
|
/// (`zitare.com/...`) auf eine konkrete `WebTarget` + Ziel-Tab.
|
|
///
|
|
/// Pure-Logic, kein State — easy testbar.
|
|
enum DeepLinkRouter {
|
|
/// Mapt eine externe URL auf eine WebShell-URL.
|
|
/// `zitare://quote/x` → `https://zitare.com/q/x`,
|
|
/// `zitare://author/x` → `https://zitare.com/a/x`,
|
|
/// `zitare://collection/x` → `https://zitare.com/c/x`.
|
|
/// `https://*` bleibt unverändert.
|
|
static func resolveToWebURL(_ url: URL, base: URL) -> URL {
|
|
if url.scheme == "zitare" {
|
|
let host = url.host ?? ""
|
|
let path = url.path
|
|
switch host {
|
|
case "quote": return base.appendingPathComponent("q\(path)")
|
|
case "author": return base.appendingPathComponent("a\(path)")
|
|
case "collection": return base.appendingPathComponent("c\(path)")
|
|
default: return base
|
|
}
|
|
}
|
|
return url
|
|
}
|
|
|
|
/// `true` wenn der Pfad in den Erkunden-Tab gehört. Sonst Lesen-Tab.
|
|
static func isExplorePath(_ path: String) -> Bool {
|
|
let prefixes = ["/explore", "/region", "/thema", "/rolle", "/epoche", "/sprache", "/search", "/t/"]
|
|
return prefixes.contains { path == $0 || path.hasPrefix($0 + "/") }
|
|
}
|
|
|
|
/// One-Shot-Resolution: URL + Base → (resolvedURL, isExploreTab).
|
|
static func route(_ url: URL, base: URL) -> (url: URL, isExplore: Bool) {
|
|
let resolved = resolveToWebURL(url, base: base)
|
|
return (resolved, isExplorePath(resolved.path))
|
|
}
|
|
}
|