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 db96868edd - Show all commits

View file

@ -4,6 +4,7 @@ import (
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"os" "os"
"strings"
) )
type OpenSearchDescription struct { type OpenSearchDescription struct {
@ -20,7 +21,17 @@ type URL struct {
Template string `xml:"template,attr"` Template string `xml:"template,attr"`
} }
// isLocalAddress 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) { func generateOpenSearchXML(config Config) {
protocol := "https://"
if isLocalAddress(config.Domain) {
protocol = "http://"
}
opensearch := OpenSearchDescription{ opensearch := OpenSearchDescription{
Xmlns: "http://a9.com/-/spec/opensearch/1.1/", Xmlns: "http://a9.com/-/spec/opensearch/1.1/",
ShortName: "Ocásek", ShortName: "Ocásek",
@ -28,7 +39,7 @@ func generateOpenSearchXML(config Config) {
Tags: "search, engine", Tags: "search, engine",
URL: URL{ URL: URL{
Type: "text/html", Type: "text/html",
Template: fmt.Sprintf("https://%s/search?q={searchTerms}", config.Domain), Template: fmt.Sprintf("%s%s/search?q={searchTerms}", protocol, config.Domain),
}, },
} }