all repos — searchix @ 5521173ea0e05bda93096b51f67c5e813cb1d87e

Search engine for NixOS, nix-darwin, home-manager and NUR users

feat: add browser search engines via opensearch description https://developer.mozilla.org/en-US/docs/Web/OpenSearch

Alan Pearce
commit

5521173ea0e05bda93096b51f67c5e813cb1d87e

parent

9437f522c2ed21950acde884cafc369ca45f4b7b

1 file changed, 36 insertions(+), 0 deletions(-)

changed files
M internal/server/mux.gointernal/server/mux.go
@@ -229,6 +229,42 @@ }
} }) + mux.HandleFunc( + "/options/{source}/opensearch.xml", + func(w http.ResponseWriter, r *http.Request) { + type openSearchData struct { + BaseURL string + Source *config.Source + } + + sourceKey := r.PathValue("source") + source := cfg.Importer.Sources[sourceKey] + if source == nil { + errorHandler(w, r, "Source not found", http.StatusNotFound) + + return + } + + w.Header().Set("Content-Type", "application/opensearchdescription+xml") + err := templates["opensearch.xml"].ExecuteTemplate( + w, + "opensearch.xml.gotmpl", + openSearchData{ + BaseURL: cfg.Web.BaseURL.String(), + Source: source, + }, + ) + if err != nil { + // no errorHandler; HTML does not make sense here + http.Error( + w, + fmt.Sprintf("Template render error: %v", err), + http.StatusInternalServerError, + ) + } + }, + ) + mux.Handle("/static/", http.FileServer(http.FS(frontend.Files))) if liveReload {