codex: add custom search engines
This commit is contained in:
@@ -74,26 +74,30 @@ extension String: RawRepresentable {
|
||||
class Settings
|
||||
{
|
||||
static let shared = Settings()
|
||||
|
||||
public enum SearchProviderSetting: String, CaseIterable {
|
||||
case google = "Google"
|
||||
case duckduckgo = "DuckDuckGo"
|
||||
case searxnor = "Searx.nor"
|
||||
case whoogle = "Whoogle.nor"
|
||||
|
||||
func provider() -> SearchProvider {
|
||||
switch self {
|
||||
case .google: return SearchProvider.google
|
||||
case .duckduckgo: return SearchProvider.duckduckgo
|
||||
case .searxnor: return SearchProvider.searxnor
|
||||
case .whoogle: return SearchProvider.whoogle
|
||||
}
|
||||
|
||||
// Map of search engine name -> URL template containing %q or %s placeholder
|
||||
// Defaults preserve the previous built-in engines
|
||||
@SettingProperty(key: "searchEngines")
|
||||
public var searchEngines: [String: String] = [
|
||||
"Google": "https://google.com/search?q=%q&gbv=1",
|
||||
"DuckDuckGo": "https://html.duckduckgo.com/html/?q=%q",
|
||||
"Searx.nor": "http://searx.nor/search?q=%q&categories=general",
|
||||
"Whoogle.nor": "http://whoogle.nor/search?q=%q"
|
||||
]
|
||||
|
||||
// Name of the default search engine from `searchEngines`
|
||||
@SettingProperty(key: "defaultSearchEngine")
|
||||
public var defaultSearchEngineName: String = "Searx.nor"
|
||||
|
||||
// Convenience to build a SearchProvider from current default
|
||||
func currentSearchProvider() -> SearchProvider {
|
||||
if let template = searchEngines[defaultSearchEngineName] {
|
||||
return SearchProvider.fromTemplate(template)
|
||||
}
|
||||
// Fallback to Google if something goes wrong
|
||||
return SearchProvider.fromTemplate("https://google.com/search?q=%q&gbv=1")
|
||||
}
|
||||
|
||||
@SettingProperty(key: "searchProvider")
|
||||
public var searchProvider: SearchProviderSetting = .searxnor
|
||||
|
||||
@SettingProperty(key: "redirectRules")
|
||||
public var redirectRules: [String: String] = [:]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user