2024-06-12 14:26:50 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
type OpenSearchDescription struct {
|
|
|
|
XMLName xml.Name `xml:"OpenSearchDescription"`
|
|
|
|
Xmlns string `xml:"xmlns,attr"`
|
|
|
|
ShortName string `xml:"ShortName"`
|
|
|
|
Description string `xml:"Description"`
|
|
|
|
Tags string `xml:"Tags"`
|
|
|
|
URL URL `xml:"Url"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type URL struct {
|
|
|
|
Type string `xml:"type,attr"`
|
|
|
|
Template string `xml:"template,attr"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateOpenSearchXML(config Config) {
|
|
|
|
opensearch := OpenSearchDescription{
|
|
|
|
Xmlns: "http://a9.com/-/spec/opensearch/1.1/",
|
|
|
|
ShortName: "Ocásek",
|
|
|
|
Description: "Search engine",
|
|
|
|
Tags: "search, engine",
|
|
|
|
URL: URL{
|
|
|
|
Type: "text/html",
|
2024-08-08 15:03:33 +02:00
|
|
|
Template: fmt.Sprintf("https://%s/search?q={searchTerms}", config.Domain),
|
2024-06-12 14:26:50 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
file, err := os.Create("static/opensearch.xml")
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error creating OpenSearch file:", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
enc := xml.NewEncoder(file)
|
|
|
|
enc.Indent(" ", " ")
|
|
|
|
if err := enc.Encode(opensearch); err != nil {
|
|
|
|
fmt.Println("Error encoding OpenSearch XML:", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("OpenSearch description file generated successfully.")
|
|
|
|
}
|