all repos — searchix @ dec2c516100350a78f0b7116bc6f9d76325e7760

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

refactor: instantiate AssetCollection explicitly

Alan Pearce
commit

dec2c516100350a78f0b7116bc6f9d76325e7760

parent

0ae74e5f6af61819e8f954960287ea14ec447834

1 file changed, 11 insertions(+), 8 deletions(-)

changed files
M internal/server/mux.gointernal/server/mux.go
@@ -71,8 +71,12 @@ return nil, fault.New("read index is nil")
} index := options.ReadIndex sortSources(cfg.Importer.Sources) + assets, err := frontend.New() + if err != nil { + return nil, fault.Wrap(err, fmsg.With("could not create frontend asset collection")) + } - errorHandler := createErrorHandler(cfg, log) + errorHandler := createErrorHandler(cfg, assets, log) top := http.NewServeMux() mux := sentryhttp.NewServeMux()
@@ -143,7 +147,7 @@ TemplateData: components.TemplateData{
ExtraHeadHTML: cfg.Web.ExtraHeadHTML, Source: source, Sources: sources, - Assets: frontend.Assets, + Assets: assets, Query: qs, }, Query: qs,
@@ -197,7 +201,7 @@ components.TemplateData{
ExtraHeadHTML: cfg.Web.ExtraHeadHTML, Sources: sources, Source: source, - Assets: frontend.Assets, + Assets: assets, }, components.ResultData{}, ).Render(w)
@@ -251,7 +255,7 @@ tdata := components.TemplateData{
ExtraHeadHTML: cfg.Web.ExtraHeadHTML, Source: source, Sources: sources, - Assets: frontend.Assets, + Assets: assets, } var baseErr error if r.Header.Get("Fetch") == "true" {
@@ -347,7 +351,7 @@ }
}) mux.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) { - asset, found := frontend.Assets.ByPath[r.URL.Path] + asset, found := assets.ByPath[r.URL.Path] if !found { http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
@@ -360,8 +364,7 @@ http.ServeFileFS(w, r, frontend.Files, asset.Filename)
}) mdb := options.ManpagesURLMap - err := mdb.Open() - if err != nil { + if err := mdb.Open(); err != nil { return nil, fault.Wrap(err, fmsg.With("failed to open manpages URL map")) } mux.HandleFunc("/man/{section}/{page}", func(w http.ResponseWriter, r *http.Request) {
@@ -395,7 +398,7 @@ }
go fw.Start(func(filename string) { log.Debug(fmt.Sprintf("got filename %s", filename)) if match, _ := path.Match("frontend/static/*", filename); match { - err := frontend.Rehash() + err := assets.Rehash() if err != nil { log.Error("failed to re-hash frontend assets", "error", err) }