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"
|
"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),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue