Added support for OpenSearch.

This commit is contained in:
Azareal 2019-05-08 15:08:38 +10:00
parent 09aa0558ab
commit af9d60cc1a
2 changed files with 20 additions and 0 deletions

View File

@ -179,6 +179,7 @@ func main() {
mapIt("routes.StaticFile")
mapIt("routes.RobotsTxt")
mapIt("routes.SitemapXml")
mapIt("routes.OpenSearchXml")
mapIt("routes.BadRoute")
mapIt("routes.HTTPSRedirect")
tmplVars.AllRouteNames = allRouteNames
@ -832,6 +833,9 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user c
//log.Print("req.URL.Path: ",req.URL.Path)
routes.StaticFile(w,req)
return nil
case "opensearch.xml":
counters.RouteViewCounter.Bump({{index .AllRouteMap "routes.OpenSearchXml"}})
return routes.OpenSearchXml(w,req)
/*case "sitemap.xml":
counters.RouteViewCounter.Bump({{index .AllRouteMap "routes.SitemapXml"}})
return routes.SitemapXml(w,req)*/

View File

@ -252,3 +252,19 @@ func APIMe(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError {
return nil
}
func OpenSearchXml(w http.ResponseWriter, r *http.Request) c.RouteError {
furl := "http"
if c.Site.EnableSsl {
furl += "s"
}
furl += "://"+c.Site.URL
w.Write([]byte(`<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>`+c.Site.Name+`</ShortName>
<InputEncoding>UTF-8</InputEncoding>
<Url type="text/html" template="`+furl+`/topics/?q={searchTerms}" />
<Url type="application/opensearchdescription+xml" rel="self" template="`+furl+`/opensearch.xml" />
<moz:SearchForm>`+furl+`</moz:SearchForm>
</OpenSearchDescription>`))
return nil
}