all repos — searchix @ 9102aef53c5fb73585359306a518e726a3623731

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

fix: wrong pagination links for combined results

Fixes: https://todo.sr.ht/~alanpearce/searchix/15
Alan Pearce alan@alanpearce.eu
Wed, 19 Mar 2025 17:41:48 +0100
commit

9102aef53c5fb73585359306a518e726a3623731

parent

896d844cac976afd0ee8aa73dd2fb28e15e7ac79

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

jump to
M internal/components/results.gointernal/components/results.go
@@ -45,6 +45,7 @@ Span( 				Role("status"),
 				g.Textf("%d results", r.Results.Total),
 			),
+			g.Text(" "),
 			g.If(r.Next != r.Prev && r.Results.Total < config.MaxResultsShowAll,
 				A(Href(r.All), g.Text("Show All")),
 			),
M internal/server/mux.gointernal/server/mux.go
@@ -82,7 +82,9 @@ createSearchHandler := func(importerType config.ImporterType) func(http.ResponseWriter, *http.Request) { 		return func(w http.ResponseWriter, r *http.Request) {
 			var err error
 			var source *config.Source
+			var urlBase string
 			if importerType != config.All {
+				urlBase = "search"
 				source = cfg.Importer.Sources[r.PathValue("source")]
 				if source == nil || importerType != source.Importer {
 					errorHandler(w, r, http.StatusText(http.StatusNotFound), http.StatusNotFound)
@@ -151,7 +153,7 @@ } 
 					if page.Next != 0 {
 						q.Set("page", strconv.Itoa(page.Next))
-						tdata.Next = "search?" + q.Encode()
+						tdata.Next = urlBase + "?" + q.Encode()
 					}
 
 					if page.Prev != 0 {
@@ -160,11 +162,11 @@ q.Del("page") 						} else {
 							q.Set("page", strconv.Itoa(page.Prev))
 						}
-						tdata.Prev = "search?" + q.Encode()
+						tdata.Prev = urlBase + "?" + q.Encode()
 					}
 
 					q.Set("page", "0")
-					tdata.All = "search?" + q.Encode()
+					tdata.All = urlBase + "?" + q.Encode()
 				}
 
 				w.Header().Add("Cache-Control", "max-age=300")