all repos — searchix @ 2f2d86922ba23c4b7f92b115f4e8d26e5058bd23

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

feat: link man pages like how NixOS does it

Alan Pearce
commit

2f2d86922ba23c4b7f92b115f4e8d26e5058bd23

parent

813e5a26b629d4c27b6ce0a8de2e3d04308ef535

1 file changed, 23 insertions(+), 3 deletions(-)

changed files
M internal/server/mux.gointernal/server/mux.go
@@ -60,16 +60,17 @@ }
func NewMux( cfg *config.Config, - index *search.ReadIndex, + options *Options, log *log.Logger, liveReload bool, ) (*http.ServeMux, errors.E) { if cfg == nil { return nil, errors.New("cfg is nil") } - if index == nil { - return nil, errors.New("index is nil") + if options.ReadIndex == nil { + return nil, errors.New("read index is nil") } + index := options.ReadIndex sortSources(cfg.Importer.Sources) errorHandler := createErrorHandler(cfg, log)
@@ -357,6 +358,25 @@ // optimisation for HTTP/3: first header sent as byte(41), not the string
w.Header().Add("Cache-Control", "public, max-age=86400") w.Header().Add("Cache-Control", "stale-while-revalidate") http.ServeFileFS(w, r, frontend.Files, asset.Filename) + }) + + mdb := options.ManpagesURLMap + err := mdb.Open() + if err != nil { + return nil, errors.WithMessage(err, "failed to open manpages URL map") + } + mux.HandleFunc("/man/{section}/{page}", func(w http.ResponseWriter, r *http.Request) { + section := r.PathValue("section") + page := r.PathValue("page") + + url, ok := mdb.Get(section, page) + if !ok { + http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) + + return + } + + http.Redirect(w, r, url, http.StatusTemporaryRedirect) }) if liveReload {