Change iOS webview baseURL handling to match macOS version.
This commit is contained in:
parent
7f392f848c
commit
59a30fdd34
|
@ -365,6 +365,9 @@ private extension ArticleRenderer {
|
|||
func renderHTML(withBody body: String) -> String {
|
||||
|
||||
var s = "<!DOCTYPE html><html><head>\n"
|
||||
if let baseURL = baseURL {
|
||||
s += ("<base href=\"" + baseURL + "\"\n>")
|
||||
}
|
||||
s += "<meta name=\"viewport\" content=\"width=device-width\">\n"
|
||||
s += title.htmlBySurroundingWithTag("title")
|
||||
s += styleString().htmlBySurroundingWithTag("style")
|
||||
|
|
|
@ -64,7 +64,7 @@ class DetailViewController: UIViewController {
|
|||
}
|
||||
let style = ArticleStylesManager.shared.currentStyle
|
||||
let html = ArticleRenderer.articleHTML(article: article, style: style)
|
||||
webView.loadHTMLString(html, baseURL: article.baseURL)
|
||||
webView.loadHTMLString(html, baseURL: nil)
|
||||
}
|
||||
|
||||
@objc func statusesDidChange(_ note: Notification) {
|
||||
|
@ -155,33 +155,5 @@ extension DetailViewController: WKNavigationDelegate {
|
|||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private extension Article {
|
||||
|
||||
var baseURL: URL? {
|
||||
var s = url
|
||||
if s == nil {
|
||||
s = feed?.homePageURL
|
||||
}
|
||||
if s == nil {
|
||||
s = feed?.url
|
||||
}
|
||||
|
||||
guard let urlString = s else {
|
||||
return nil
|
||||
}
|
||||
var urlComponents = URLComponents(string: urlString)
|
||||
if urlComponents == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Can’t use url-with-fragment as base URL. The webview won’t load. See scripting.com/rss.xml for example.
|
||||
urlComponents!.fragment = nil
|
||||
guard let url = urlComponents!.url, url.scheme == "http" || url.scheme == "https" else {
|
||||
return nil
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue