Redirect Rules: implements redirect rules UI
This commit is contained in:
@@ -28,6 +28,19 @@ public struct SettingProperty<T: RawRepresentable>
|
||||
}
|
||||
}
|
||||
|
||||
extension Dictionary: RawRepresentable where Key == String, Value == String {
|
||||
public typealias RawValue = [String: String]
|
||||
|
||||
public init?(rawValue: [String : String]) {
|
||||
self.init()
|
||||
self.merge(rawValue, uniquingKeysWith: { $1 })
|
||||
}
|
||||
|
||||
public var rawValue: [String : String] {
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
||||
class Settings
|
||||
{
|
||||
static let shared = Settings()
|
||||
@@ -50,4 +63,18 @@ class Settings
|
||||
|
||||
@SettingProperty(key: "searchProvider")
|
||||
public var searchProvider: SearchProviderSetting = .searxnor
|
||||
|
||||
@SettingProperty(key: "redirectRules")
|
||||
public var redirectRules: [String: String] = [:]
|
||||
|
||||
func redirectRule(for url: URL) -> URL? {
|
||||
if var components = URLComponents(url: url, resolvingAgainstBaseURL: false), let host = url.host {
|
||||
if let alternateHost = redirectRules[host] {
|
||||
components.host = alternateHost
|
||||
return components.url
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user