all repos — searchix @ 0e24d9cde2f9a9e94315fa463d6503ddd64255c2

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

refactor: reduce use of pointers in particular, Source can no longer be nil. Instantiate a Source with an Importer of All instead

Alan Pearce
commit

0e24d9cde2f9a9e94315fa463d6503ddd64255c2

parent

05838942b9468dd1efb6d295a206730fa82264c0

1 file changed, 7 insertions(+), 22 deletions(-)

changed files
M internal/components/page.gointernal/components/page.go
@@ -25,15 +25,15 @@ g.If(len(tdata.Sources) > 0,
Link( Rel("search"), Type("application/opensearchdescription+xml"), - TitleAttr("Searchix "+sourceNameAndType(nil)), + TitleAttr("Searchix "+tdata.Source.String()), Href(joinPath("opensearch.xml")), ), ), - g.Map(tdata.Sources, func(source *config.Source) g.Node { + g.Map(tdata.Sources, func(source config.Source) g.Node { return Link( Rel("search"), Type("application/opensearchdescription+xml"), - TitleAttr("Searchix "+sourceNameAndType(source)), + TitleAttr("Searchix "+source.String()), Href(joinPath("/", source.Importer.String(), source.Key, "opensearch.xml")), ) }),
@@ -45,18 +45,18 @@ H1(A(Href("/"), g.Text("Searchix"))),
g.If(len(tdata.Sources) > 0, A( c.Classes{ - "current": tdata.Source == nil, + "current": tdata.Source.Importer == config.All, }, g.If( - tdata.Source == nil, + tdata.Source.Importer == config.All, Href("/"), Href(joinPathQuery("/", tdata.Query)), ), g.Text("All"), ), ), - g.Map(tdata.Sources, func(source *config.Source) g.Node { - if tdata.Source != nil && tdata.Source.Name == source.Name { + g.Map(tdata.Sources, func(source config.Source) g.Node { + if tdata.Source.Importer != config.All && tdata.Source.Name == source.Name { return A( Class("current"), Href(
@@ -131,21 +131,6 @@ }
func script(s *frontend.Asset) g.Node { return Script(Src(s.ImmutablePath), Defer()) -} - -func sourceNameAndType(source *config.Source) string { - if source == nil { - return "Combined" - } - - switch source.Importer { - case config.Options: - return source.Name + " " + source.Importer.String() - case config.Packages: - return source.Name - } - - return "" } func joinPath(base string, parts ...string) string {