zitare-native/Sources/App/DeepLinkRouter.swift
Till JS 1d770123f5 η-0: De-Hybrid — WKWebView raus, native Tabs mit Platzhaltern
Lift von Hybrid (WKWebView für Lesen/Erkunden) auf fully-native ist
beschlossen. Diese Phase entfernt die WebShell-Infrastruktur; das volle
native Read-Surface folgt in η-2..η-5 nach docs/NATIVE_LIFT_PLAN.md.

- ManaWebShell-Dep raus aus project.yml
- Sources/Core/WebShell/CookieBridge.swift gelöscht
- RootView auf vier native Tabs (Lesen + Erkunden = Platzhalter,
  Submit + Konto unverändert nativ)
- DocComments in DeepLinkRouter / AppConfig / Account / Settings von
  WebView-Verweisen befreit
- CLAUDE.md Invarianten von Hybrid auf η umgestellt (13 Invarianten,
  pure SwiftUI + Offline-first + SafariView-Ausnahme für Legal)
- PLAN.md auf η-0 + Phasenübersicht η-0..η-10
- AppConfigTests.test_keychainService_matchesSharedGroup auf
  ManaSharedKeychainGroup aktualisiert (war drift seit Cross-App-SSO)

Verifikation:
- xcodebuild iOS-Simulator iPhone 16e: BUILD SUCCEEDED
- nm ZitareNative | grep WKWebView: 0 Referenzen
- otool -L: kein WebKit-Framework-Link
- 20/20 Tests grün

Cross-Repo-Follow-up (η-1 Blocker):
- zitare/apps/zitare/ muss index-full.json + 7 Stammdaten-JSONs liefern
- zitare/apps/api/ Volltext-Search-Endpoint bestätigen/ergänzen

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 12:32:05 +02:00

43 lines
1.9 KiB
Swift

import Foundation
/// Routet sowohl Custom-Scheme- (`zitare://`) als auch Universal-Link-URLs
/// (`zitare.com/...`) auf eine normalisierte URL + Ziel-Tab.
///
/// **η-0 (de-Hybrid):** Die URL ist nicht mehr WebView-Target, sondern
/// Eingabe für das native `NavigationPath`-Routing in η-2. Path-Struktur
/// (`/q/<slug>`, `/a/<slug>`, `/c/<slug>`, `/thema/<slug>` etc.) bleibt
/// 1:1 wie im Web-Repo die Native-Views matchen die gleichen Slugs.
///
/// Pure-Logic, kein State easy testbar.
enum DeepLinkRouter {
/// Normalisiert eine externe URL auf den kanonischen `https://`-Pfad.
/// `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))
}
}