all repos — searchix @ 560b6350141050cd4b9aa5717acf5c241996a978

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

fix: changing facets reverted to combined search

Alan Pearce
commit

560b6350141050cd4b9aa5717acf5c241996a978

parent

8a29e39f16bec9ff7d3c264173862acdcfa272c5

3 files changed, 16 insertions(+), 7 deletions(-)

changed files
M internal/config/structs.gointernal/config/structs.go
@@ -5,6 +5,7 @@ // keep config structs here so that lll ignores the long lines (go doesn't support multi-line struct tags)
import ( "fmt" + "net/url" "path/filepath" "strings"
@@ -90,3 +91,14 @@ func (source *Source) JoinFilePath(name string) string {
//nolint:forbidigo // is not absolute return filepath.Join("sources", source.Key, name) } + +func (source *Source) LocalURL() *url.URL { + p, err := url.JoinPath("/", source.Importer.String(), source.Key, "/") + if err != nil { + panic(err.Error()) + } + + return &url.URL{ + Path: p, + } +}
M internal/server/global.gointernal/server/global.go
@@ -37,9 +37,9 @@ source: source,
mux: http.NewServeMux(), } - h.mux.HandleFunc("/search", h.Search) - h.mux.HandleFunc("/{id}", h.Detail) - h.mux.HandleFunc("/opensearch.xml", h.OpenSearchXML) + h.mux.HandleFunc(source.LocalURL().JoinPath("/search").String(), h.Search) + h.mux.HandleFunc(source.LocalURL().JoinPath("/{id}").String(), h.Detail) + h.mux.HandleFunc(source.LocalURL().JoinPath("/opensearch.xml").String(), h.OpenSearchXML) return h }
M internal/server/mux.gointernal/server/mux.go
@@ -95,10 +95,7 @@ })
} for _, source := range cfg.Importer.Sources { - sh := handler.NewSourceHandler(source) - importerPath := path.Join("/", source.Importer.String(), source.Key) - - mux.Handle(importerPath+"/", http.StripPrefix(importerPath, sh)) + mux.Handle(source.LocalURL().String(), handler.NewSourceHandler(source)) } top := http.NewServeMux()