From d3bdc8065da33f0599e54bc8a1047abb868be8c9 Mon Sep 17 00:00:00 2001 From: partisan Date: Wed, 18 Jun 2025 13:55:13 +0200 Subject: [PATCH] Fixed opensearch.xml --- open-search.go | 47 ++++++++++++++++++++++++++++++----------- templates/files.html | 6 ++++-- templates/forums.html | 6 ++++-- templates/images.html | 6 ++++-- templates/map.html | 6 ++++-- templates/music.html | 6 ++++-- templates/privacy.html | 3 +++ templates/search.html | 5 +++-- templates/settings.html | 6 ++++-- templates/text.html | 6 ++++-- templates/videos.html | 6 ++++-- 11 files changed, 73 insertions(+), 30 deletions(-) diff --git a/open-search.go b/open-search.go index fefce8f..5c07b47 100644 --- a/open-search.go +++ b/open-search.go @@ -7,31 +7,52 @@ import ( ) 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"` - URLs []URL `xml:"Url"` + XMLName xml.Name `xml:"OpenSearchDescription"` + Xmlns string `xml:"xmlns,attr"` + ShortName string `xml:"ShortName"` + LongName string `xml:"LongName"` + Description string `xml:"Description"` + Tags string `xml:"Tags,omitempty"` + InputEncoding string `xml:"InputEncoding"` + OutputEncoding string `xml:"OutputEncoding"` + Image *Image `xml:"Image,omitempty"` + URLs []URL `xml:"Url"` } type URL struct { Type string `xml:"type,attr"` + Method string `xml:"method,attr,omitempty"` Template string `xml:"template,attr"` } -func generateOpenSearchXML(config Config) { - // Ensure that language is initialized in `main` before calling this function +type Image struct { + Height int `xml:"height,attr"` + Width int `xml:"width,attr"` + Type string `xml:"type,attr"` + URL string `xml:",chardata"` +} +func generateOpenSearchXML(config Config) { baseURL := addProtocol(config.Domain) + opensearch := OpenSearchDescription{ - Xmlns: "http://a9.com/-/spec/opensearch/1.1/", - ShortName: Translate("site_name"), - Description: Translate("site_description"), - Tags: Translate("site_tags"), + Xmlns: "http://a9.com/-/spec/opensearch/1.1/", + ShortName: Translate("site_name"), + LongName: Translate("site_name") + " Search", + Description: Translate("site_description"), + Tags: Translate("site_tags"), + InputEncoding: "UTF-8", + OutputEncoding: "UTF-8", + Image: &Image{ + Height: 16, + Width: 16, + Type: "image/x-icon", + URL: fmt.Sprintf("%s/favicon.ico", baseURL), + }, URLs: []URL{ { Type: "text/html", + Method: "get", Template: fmt.Sprintf("%s/search?q={searchTerms}", baseURL), }, { @@ -48,6 +69,8 @@ func generateOpenSearchXML(config Config) { } defer file.Close() + file.WriteString(`` + "\n") + enc := xml.NewEncoder(file) enc.Indent(" ", " ") if err := enc.Encode(opensearch); err != nil { diff --git a/templates/files.html b/templates/files.html index 2045a29..ec6127d 100755 --- a/templates/files.html +++ b/templates/files.html @@ -12,8 +12,10 @@ - + + + + diff --git a/templates/forums.html b/templates/forums.html index d95c69b..4c13e8d 100755 --- a/templates/forums.html +++ b/templates/forums.html @@ -13,9 +13,11 @@ - + + + + diff --git a/templates/images.html b/templates/images.html index e65facf..35d92ae 100755 --- a/templates/images.html +++ b/templates/images.html @@ -23,8 +23,10 @@ - + + + + diff --git a/templates/map.html b/templates/map.html index 004df64..bdfcccf 100644 --- a/templates/map.html +++ b/templates/map.html @@ -12,8 +12,10 @@ - + + + + diff --git a/templates/music.html b/templates/music.html index 878c1b6..fe4026a 100644 --- a/templates/music.html +++ b/templates/music.html @@ -14,8 +14,10 @@ - + + + + diff --git a/templates/privacy.html b/templates/privacy.html index 0e86327..05fb2b0 100644 --- a/templates/privacy.html +++ b/templates/privacy.html @@ -13,6 +13,9 @@ + + + diff --git a/templates/search.html b/templates/search.html index 714dc38..a1a8579 100755 --- a/templates/search.html +++ b/templates/search.html @@ -65,8 +65,9 @@ - + + + diff --git a/templates/settings.html b/templates/settings.html index d00b540..c214151 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -12,8 +12,10 @@ - + + + + diff --git a/templates/text.html b/templates/text.html index ea9448f..b49a7ef 100755 --- a/templates/text.html +++ b/templates/text.html @@ -13,8 +13,10 @@ - + + + + diff --git a/templates/videos.html b/templates/videos.html index 318cd4b..a8a3636 100644 --- a/templates/videos.html +++ b/templates/videos.html @@ -12,8 +12,10 @@ - + + + +