Use correct base URL for web view content
This commit is contained in:
parent
755f98a2e2
commit
85819ea6aa
|
@ -53,9 +53,7 @@ class ReadViewController: UIViewController {
|
|||
webView.navigationDelegate = self
|
||||
webView.uiDelegate = self
|
||||
if let content = itemContentHTML() {
|
||||
// todo: using the bundle url is the only way to get the stylesheet to load, but feels wrong
|
||||
// will break, e.g., images with relative urls
|
||||
webView.loadHTMLString(content, baseURL: Bundle.main.bundleURL)
|
||||
webView.loadHTMLString(content, baseURL: item.url)
|
||||
}
|
||||
view.addSubview(webView)
|
||||
|
||||
|
@ -68,6 +66,8 @@ class ReadViewController: UIViewController {
|
|||
|
||||
}
|
||||
|
||||
private static let css = try! String(contentsOf: Bundle.main.url(forResource: "read", withExtension: "css")!)
|
||||
|
||||
private func itemContentHTML() -> String? {
|
||||
guard let content = item.content else {
|
||||
return nil
|
||||
|
@ -100,7 +100,7 @@ class ReadViewController: UIViewController {
|
|||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
|
||||
<link rel="stylesheet" href="\(Bundle.main.url(forResource: "read", withExtension: "css")!.absoluteString)" />
|
||||
<style>\(ReadViewController.css)</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="item-info">
|
||||
|
@ -119,7 +119,7 @@ class ReadViewController: UIViewController {
|
|||
extension ReadViewController: WKNavigationDelegate {
|
||||
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction) async -> WKNavigationActionPolicy {
|
||||
let url = navigationAction.request.url!
|
||||
if url == Bundle.main.bundleURL {
|
||||
if url == item.url {
|
||||
return .allow
|
||||
} else {
|
||||
present(SFSafariViewController(url: url), animated: true)
|
||||
|
|
Loading…
Reference in New Issue