Change iOS webview baseURL handling to match macOS version.

This commit is contained in:
Maurice Parker 2019-04-19 07:37:47 -05:00
parent 7f392f848c
commit 59a30fdd34
2 changed files with 4 additions and 29 deletions

View File

@ -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")

View File

@ -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
}
// Cant use url-with-fragment as base URL. The webview wont 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
}
}