work branch into the main #8

Merged
partisan merged 34 commits from work into main 2024-08-18 10:08:43 +00:00
Showing only changes of commit 283096d299 - Show all commits

View file

@ -21,25 +21,38 @@ type URL struct {
Template string `xml:"template,attr"`
}
// isLocalAddress checks if the domain is a local address
// Checks if the URL already includes a protocol
func hasProtocol(url string) bool {
return strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://")
}
// Checks if the domain is a local address
func isLocalAddress(domain string) bool {
return domain == "localhost" || strings.HasPrefix(domain, "127.") || strings.HasPrefix(domain, "192.168.") || strings.HasPrefix(domain, "10.")
}
func generateOpenSearchXML(config Config) {
protocol := "https://"
if isLocalAddress(config.Domain) {
protocol = "http://"
// Ensures that HTTP or HTTPS is befor the adress if needed
func addProtocol(domain string) string {
if hasProtocol(domain) {
return domain
}
if isLocalAddress(domain) {
return "http://" + domain
}
return "https://" + domain
}
func generateOpenSearchXML(config Config) {
baseURL := addProtocol(config.Domain)
opensearch := OpenSearchDescription{
Xmlns: "http://a9.com/-/spec/opensearch/1.1/",
ShortName: "Ocásek",
ShortName: "Search Engine",
Description: "Search engine",
Tags: "search, engine",
URL: URL{
Type: "text/html",
Template: fmt.Sprintf("%s%s/search?q={searchTerms}", protocol, config.Domain),
Template: fmt.Sprintf("%s/search?q={searchTerms}", baseURL),
},
}