diff --git a/http.go b/http.go
index dd4267c..5931761 100644
--- a/http.go
+++ b/http.go
@@ -227,6 +227,7 @@ func (a *goBlog) buildStaticHandlersRouters() error {
a.searchRouter.Use(a.cache.cacheMiddleware)
a.searchRouter.Get("/", a.serveSearch)
a.searchRouter.Post("/", a.serveSearch)
+ a.searchRouter.Get("/opensearch.xml", a.serveOpenSearch)
searchResultPath := "/" + searchPlaceholder
a.searchRouter.Get(searchResultPath, a.serveSearchResult)
a.searchRouter.Get(searchResultPath+feedPath, a.serveSearchResult)
diff --git a/opensearch.go b/opensearch.go
new file mode 100644
index 0000000..f1441a1
--- /dev/null
+++ b/opensearch.go
@@ -0,0 +1,28 @@
+package main
+
+import (
+ "fmt"
+ "net/http"
+)
+
+func (a *goBlog) serveOpenSearch(w http.ResponseWriter, r *http.Request) {
+ blog := r.Context().Value(blogContextKey).(string)
+ b := a.cfg.Blogs[blog]
+ title := b.Title
+ sURL := a.cfg.Server.PublicAddress + b.getRelativePath(b.Search.Path)
+ xml := fmt.Sprintf(""+
+ "%s%s"+
+ ""+
+ "%s"+
+ "",
+ title, title, sURL, sURL)
+ w.Header().Set(contentType, "application/opensearchdescription+xml")
+ writeMinified(w, contentTypeXML, []byte(xml))
+}
+
+func openSearchUrl(b *configBlog) string {
+ if b.Search != nil && b.Search.Enabled {
+ return b.getRelativePath(b.Search.Path + "/opensearch.xml")
+ }
+ return ""
+}
diff --git a/render.go b/render.go
index f80187c..16f123d 100644
--- a/render.go
+++ b/render.go
@@ -180,7 +180,8 @@ func (a *goBlog) initRendering() error {
}
return
},
- "geotitle": a.db.geoTitle,
+ "geotitle": a.db.geoTitle,
+ "opensearch": openSearchUrl,
}
baseTemplate, err := template.New("base").Funcs(templateFunctions).ParseFiles(path.Join(templatesDir, templateBase+templatesExt))
diff --git a/templates/base.gohtml b/templates/base.gohtml
index 36bf290..6c89dae 100644
--- a/templates/base.gohtml
+++ b/templates/base.gohtml
@@ -20,6 +20,10 @@
{{ end }}
{{ end }}
+ {{ $os := opensearch .Blog }}
+ {{ if $os }}
+
+ {{ end }}
{{ include "header" . }}
{{ block "main" . }}{{ end }}
{{ include "footer" . }}