codex: add custom search engines

This commit is contained in:
2025-09-28 21:10:31 -07:00
parent 797c4c7c52
commit 265d393cdc
5 changed files with 108 additions and 39 deletions

View File

@@ -9,6 +9,18 @@ import Foundation
class SearchProvider
{
// Build a provider from a URL template. Template should contain %q or %s
// which will be replaced with the sanitized query string.
static func fromTemplate(_ template: String) -> SearchProvider {
SearchProvider(resolver: { query in
let sanitized = query.sanitized()
let replaced = template
.replacingOccurrences(of: "%q", with: sanitized)
.replacingOccurrences(of: "%s", with: sanitized)
return URL(string: replaced) ?? URL(string: "https://google.com/search?q=\(sanitized)&gbv=1")!
})
}
static let google = SearchProvider(resolver: { query in
// gbv=1: no JS
URL(string: "https://google.com/search?q=\(query.sanitized())&gbv=1")!