[iOS] - Fix an issue with reader-mode page language not specified (#27676)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at https://mozilla.org/MPL/2.0/. -->
|
||||
<html>
|
||||
<html lang="%READER-PAGE-LANGUAGE%">
|
||||
|
||||
<head>
|
||||
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
|
||||
|
||||
@@ -33,6 +33,11 @@ struct ReaderModeUtils {
|
||||
.replacingOccurrences(of: "%READER-STYLE%", with: initialStyle.encode())
|
||||
.replacingOccurrences(of: "%READER-DOMAIN%", with: simplifyDomain(readabilityResult.domain))
|
||||
.replacingOccurrences(of: "%READER-URL%", with: readabilityResult.url)
|
||||
.replacingOccurrences(
|
||||
of: "%READER-PAGE-LANGUAGE%",
|
||||
with: readabilityResult.documentLanguage.javaScriptEscapedString?.unquotedIfNecessary
|
||||
?? ""
|
||||
)
|
||||
.replacingOccurrences(
|
||||
of: "%READER-TITLE%",
|
||||
with: readabilityResult.title.javaScriptEscapedString?.unquotedIfNecessary
|
||||
|
||||
+5
@@ -88,6 +88,11 @@ function checkReadability() {
|
||||
readabilityResult.cspMetaTags = [...cspMetaTags].map((e) => new XMLSerializer().serializeToString(e));
|
||||
}
|
||||
|
||||
let documentLanguage = document.documentElement.lang || document.querySelector('meta[http-equiv="Content-Language"]')?.content || null;
|
||||
if (documentLanguage) {
|
||||
readabilityResult.documentLanguage = documentLanguage;
|
||||
}
|
||||
|
||||
debug({Type: "ReaderModeStateChange", Value: readabilityResult !== null ? "Available" : "Unavailable"});
|
||||
webkit.messageHandlers.readerModeMessageHandler.postMessage({"securityToken": SECURITY_TOKEN, "data": {Type: "ReaderModeStateChange", Value: readabilityResult !== null ? "Available" : "Unavailable"}});
|
||||
webkit.messageHandlers.readerModeMessageHandler.postMessage({"securityToken": SECURITY_TOKEN, "data": {Type: "ReaderContentParsed", Value: readabilityResult}});
|
||||
|
||||
+8
-1
@@ -169,6 +169,7 @@ struct ReadabilityResult {
|
||||
var domain = ""
|
||||
var url = ""
|
||||
var content = ""
|
||||
var documentLanguage = ""
|
||||
var title = ""
|
||||
var credits = ""
|
||||
var direction = "auto"
|
||||
@@ -191,6 +192,9 @@ struct ReadabilityResult {
|
||||
if let content = dict["content"] as? String {
|
||||
self.content = content
|
||||
}
|
||||
if let documentLanguage = dict["documentLanguage"] as? String {
|
||||
self.documentLanguage = documentLanguage
|
||||
}
|
||||
if let title = dict["title"] as? String {
|
||||
self.title = title
|
||||
}
|
||||
@@ -214,6 +218,7 @@ struct ReadabilityResult {
|
||||
let domain = object["domain"].string
|
||||
let url = object["url"].string
|
||||
let content = object["content"].string
|
||||
let documentLanguage = object["documentLanguage"].string
|
||||
let title = object["title"].string
|
||||
let credits = object["credits"].string
|
||||
let direction = object["dir"].string
|
||||
@@ -226,6 +231,7 @@ struct ReadabilityResult {
|
||||
self.domain = domain!
|
||||
self.url = url!
|
||||
self.content = content!
|
||||
self.documentLanguage = documentLanguage ?? ""
|
||||
self.title = title!
|
||||
self.credits = credits!
|
||||
self.direction = direction ?? "auto"
|
||||
@@ -235,7 +241,8 @@ struct ReadabilityResult {
|
||||
/// Encode to a dictionary, which can then for example be json encoded
|
||||
func encode() -> [String: Any] {
|
||||
return [
|
||||
"domain": domain, "url": url, "content": content, "title": title, "credits": credits,
|
||||
"domain": domain, "url": url, "content": content, "documentLanguage": documentLanguage,
|
||||
"title": title, "credits": credits,
|
||||
"dir": direction, "cspMetaTags": cspMetaTags,
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user