all repos — searchix @ 7077a3748fa545e8dee83d4f3464c55b4b459183

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

feat: allow adding extra HTML to the body via configuration

Alan Pearce
commit

7077a3748fa545e8dee83d4f3464c55b4b459183

parent

fe79b4509dd580542fa28186673826df603677bb

1 file changed, 18 insertions(+), 17 deletions(-)

changed files
M internal/server/mux.gointernal/server/mux.go
@@ -50,12 +50,12 @@
const jsSnippet = template.HTML(livereload.JsSnippet) // #nosec G203 type TemplateData struct { - LiveReload template.HTML - Sources map[string]*importer.Source - Source importer.Source - Query string - Results bool - SourceResult *bleve.SearchResult + Sources map[string]*importer.Source + Source importer.Source + Query string + Results bool + SourceResult *bleve.SearchResult + ExtraBodyHTML template.HTML } type ResultData[T options.NixOption] struct {
@@ -109,11 +109,11 @@ }
top := http.NewServeMux() mux := http.NewServeMux() - indexData := TemplateData{ - LiveReload: jsSnippet, - Sources: config.Sources, - } mux.HandleFunc("/{$}", func(w http.ResponseWriter, _ *http.Request) { + indexData := TemplateData{ + ExtraBodyHTML: config.ExtraBodyHTML, + Sources: config.Sources, + } err := templates["index"].ExecuteTemplate(w, "index.gotmpl", indexData) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -157,9 +157,9 @@ }
tdata := ResultData[options.NixOption]{ TemplateData: TemplateData{ - LiveReload: jsSnippet, - Source: *source, - Sources: config.Sources, + ExtraBodyHTML: config.ExtraBodyHTML, + Source: *source, + Sources: config.Sources, }, ResultsPerPage: search.ResultsPerPage, Query: qs,
@@ -216,10 +216,10 @@ return
} err = templates["search"].Execute(w, TemplateData{ - LiveReload: jsSnippet, - Sources: config.Sources, - Source: *source, - SourceResult: sourceResult, + ExtraBodyHTML: config.ExtraBodyHTML, + Sources: config.Sources, + Source: *source, + SourceResult: sourceResult, }) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -233,6 +233,7 @@ mux.Handle("/static/", http.FileServer(http.FS(frontend.Files)))
if runtimeConfig.LiveReload { applyDevModeOverrides(config) + config.ExtraBodyHTML = jsSnippet liveReload := livereload.New() liveReload.Start() top.Handle("/livereload", liveReload)