all repos — searchix @ 05a32bda78911772cb8b09f37bacbcf851a4ddba

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

feat: default to combined search on root path

Alan Pearce
commit

05a32bda78911772cb8b09f37bacbcf851a4ddba

parent

0de558cbda214106f46d26ace622df5dbb3266fd

4 files changed, 15 insertions(+), 29 deletions(-)

jump to
D internal/components/homepage.templ
@@ -1,10 +0,0 @@
-package components - -templ Homepage(tdata TemplateData) { - @Page(tdata) { - <p> - Search Nix Packages and options from NixOS, Darwin and Home-Manager - </p> - <a href="https://git.sr.ht/~alanpearce/searchix">Source code</a> - } -}
M internal/components/page.templinternal/components/page.templ
@@ -29,7 +29,7 @@ <link
rel="search" type="application/opensearchdescription+xml" title={ "Searchix " + sourceNameAndType(nil) } - href={ string(joinPath("/all", "opensearch.xml")) } + href={ string(joinPath("opensearch.xml")) } /> for _, source := range tdata.Sources { <link
@@ -49,9 +49,9 @@ if tdata.Source == nil {
if tdata.SourceResult != nil || tdata.Query != "" { class="current" } - href="/all/search" + href="/" } else { - href={ joinPathQuery("/all/search", tdata.Query) } + href={ joinPathQuery("/", tdata.Query) } } >All</a> for _, source := range tdata.Sources {
@@ -71,6 +71,7 @@ { children... }
</main> <footer> Made by <a href="https://alanpearce.eu">Alan Pearce</a>. + <a href="https://git.sr.ht/~alanpearce/searchix">Source code</a> <a href="https://todo.sr.ht/~alanpearce/searchix">Report issues</a> </footer> </body>
M internal/components/search.templinternal/components/search.templ
@@ -23,6 +23,9 @@ }
templ SearchPage(tdata TemplateData, r ResultData) { @Page(tdata) { + <p> + Search Nix packages and options from NixOS, Darwin and Home-Manager + </p> @script(tdata.Assets.ByPath["/static/search.js"]) @Search(tdata, r) <section id="results" role="list" aria-label="search results">
@@ -36,5 +39,6 @@ <p class="notice">
Everything should work fine without JavaScript. If that is not the case, <a href="https://todo.sr.ht/~alanpearce/searchix">report an issue</a> </p> </noscript> + <a href="https://git.sr.ht/~alanpearce/searchix">Source code</a> } }
M internal/server/mux.gointernal/server/mux.go
@@ -71,18 +71,6 @@ errorHandler := createErrorHandler(cfg, log)
top := http.NewServeMux() mux := sentryhttp.NewServeMux() - mux.HandleFunc("/{$}", func(w http.ResponseWriter, r *http.Request) { - indexData := components.TemplateData{ - ExtraHeadHTML: cfg.Web.ExtraHeadHTML, - Sources: sources, - Assets: frontend.Assets, - } - w.Header().Add("Cache-Control", "max-age=86400") - err := components.Homepage(indexData).Render(r.Context(), w) - if err != nil { - errorHandler(w, r, err.Error(), http.StatusInternalServerError) - } - }) const searchTimeout = 1 * time.Second createSearchHandler := func(importerType config.ImporterType) func(http.ResponseWriter, *http.Request) {
@@ -213,9 +201,11 @@ }
} } - mux.HandleFunc("/all/search", createSearchHandler(config.All)) + mux.HandleFunc("/{$}", createSearchHandler(config.All)) mux.HandleFunc("/options/{source}/search", createSearchHandler(config.Options)) mux.HandleFunc("/packages/{source}/search", createSearchHandler(config.Packages)) + + mux.Handle("/all/search", http.RedirectHandler("/", http.StatusFound)) createSourceIDHandler := func(importerType config.ImporterType) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) {
@@ -317,18 +307,19 @@ }
mux.HandleFunc("/options/{source}/opensearch.xml", createOpenSearchXMLHandler(config.Options)) mux.HandleFunc("/packages/{source}/opensearch.xml", createOpenSearchXMLHandler(config.Packages)) - mux.HandleFunc("/all/opensearch.xml", func(w http.ResponseWriter, _ *http.Request) { + mux.Handle("/all/opensearch.xml", http.RedirectHandler("/opensearch.xml", http.StatusFound)) + mux.HandleFunc("/opensearch.xml", func(w http.ResponseWriter, _ *http.Request) { w.Header().Add("Cache-Control", "max-age=604800") w.Header().Set("Content-Type", "application/opensearchdescription+xml") osd := &opensearch.Description{ ShortName: "Searchix Combined", LongName: "Search nix options and packages with Searchix", Description: "Search nix options and packages with Searchix", - SearchForm: cfg.Web.BaseURL.JoinPath("all/search"), + SearchForm: cfg.Web.BaseURL.JoinPath(), URL: opensearch.URL{ Method: "get", Type: "text/html", - Template: cfg.Web.BaseURL.JoinPath("all/search"). + Template: cfg.Web.BaseURL.JoinPath(). AddRawQuery("query", "{searchTerms}"), }, }