update open-search
This commit is contained in:
parent
5294421190
commit
75921ef7b5
1 changed files with 12 additions and 1 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/xml"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type OpenSearchDescription struct {
|
||||
|
@ -20,7 +21,17 @@ type URL struct {
|
|||
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) {
|
||||
protocol := "https://"
|
||||
if isLocalAddress(config.Domain) {
|
||||
protocol = "http://"
|
||||
}
|
||||
|
||||
opensearch := OpenSearchDescription{
|
||||
Xmlns: "http://a9.com/-/spec/opensearch/1.1/",
|
||||
ShortName: "Ocásek",
|
||||
|
@ -28,7 +39,7 @@ func generateOpenSearchXML(config Config) {
|
|||
Tags: "search, engine",
|
||||
URL: URL{
|
||||
Type: "text/html",
|
||||
Template: fmt.Sprintf("https://%s/search?q={searchTerms}", config.Domain),
|
||||
Template: fmt.Sprintf("%s%s/search?q={searchTerms}", protocol, config.Domain),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue