all repos — searchix @ 631c02ac689b3366987918737e2b09f52fb16dda

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

feat: dynamically link to sources
Alan Pearce alan@alanpearce.eu
Thu, 09 May 2024 19:36:03 +0200
commit

631c02ac689b3366987918737e2b09f52fb16dda

parent

f42dfe7b5fd3d60c9558eb520d33c7c8fd1ba201

2 files changed, 5 insertions(+), 3 deletions(-)

jump to
M frontend/templates/index.gotmplfrontend/templates/index.gotmpl
@@ -11,9 +11,9 @@ <body>     <header>
       <nav>
         <h1><a href="/">Searchix</a></h1>
-        <a href="/options/nixos/search">NixOS</a>
-        <a href="/options/darwin/search">Darwin</a>
-        <a href="/options/home-manager/search">Home Manager</a>
+        {{- range $key, $value := .Sources }}
+          <a href="/options/{{ $key }}/search">{{ $value.Name }}</a>
+        {{- end }}
       </nav>
     </header>
     <main>
M internal/server/server.gointernal/server/server.go
@@ -63,6 +63,7 @@ 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
@@ -125,6 +126,7 @@ top := http.NewServeMux() 	mux := http.NewServeMux()
 	indexData := TemplateData{
 		LiveReload: jsSnippet,
+		Sources:    config.Sources,
 	}
 	mux.HandleFunc("/{$}", func(w http.ResponseWriter, _ *http.Request) {
 		err := templates["index"].ExecuteTemplate(w, "index.gotmpl", indexData)