2021-06-09 20:44:22 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2021-06-18 12:32:03 +00:00
|
|
|
|
2021-06-28 20:17:18 +00:00
|
|
|
"go.goblog.app/app/pkgs/contenttype"
|
2021-06-09 20:44:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (a *goBlog) serveOpenSearch(w http.ResponseWriter, r *http.Request) {
|
2021-07-27 10:51:08 +00:00
|
|
|
blog := r.Context().Value(blogKey).(string)
|
2021-06-09 20:44:22 +00:00
|
|
|
b := a.cfg.Blogs[blog]
|
2021-08-05 12:53:22 +00:00
|
|
|
title := a.renderMdTitle(b.Title)
|
2021-07-12 14:19:28 +00:00
|
|
|
sURL := a.getFullAddress(b.getRelativePath(defaultIfEmpty(b.Search.Path, defaultSearchPath)))
|
2021-06-09 20:44:22 +00:00
|
|
|
xml := fmt.Sprintf("<?xml version=\"1.0\"?><OpenSearchDescription xmlns=\"http://a9.com/-/spec/opensearch/1.1/\" xmlns:moz=\"http://www.mozilla.org/2006/browser/search/\">"+
|
|
|
|
"<ShortName>%s</ShortName><Description>%s</Description>"+
|
|
|
|
"<Url type=\"text/html\" method=\"post\" template=\"%s\"><Param name=\"q\" value=\"{searchTerms}\" /></Url>"+
|
|
|
|
"<moz:SearchForm>%s</moz:SearchForm>"+
|
|
|
|
"</OpenSearchDescription>",
|
|
|
|
title, title, sURL, sURL)
|
|
|
|
w.Header().Set(contentType, "application/opensearchdescription+xml")
|
2021-06-18 12:32:03 +00:00
|
|
|
_, _ = a.min.Write(w, contenttype.XML, []byte(xml))
|
2021-06-09 20:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func openSearchUrl(b *configBlog) string {
|
|
|
|
if b.Search != nil && b.Search.Enabled {
|
2021-07-12 14:19:28 +00:00
|
|
|
return b.getRelativePath(defaultIfEmpty(b.Search.Path, defaultSearchPath) + "/opensearch.xml")
|
2021-06-09 20:44:22 +00:00
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|