all repos — searchix @ 896d844cac976afd0ee8aa73dd2fb28e15e7ac79

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

feat: Convert templ components to gomponents

Alan Pearce
commit

896d844cac976afd0ee8aa73dd2fb28e15e7ac79

parent

1183108baa44fde88944e9207fb7763668c2b448

1 file changed, 56 insertions(+), 0 deletions(-)

changed files
A internal/components/combined.go
@@ -0,0 +1,56 @@
+package components + +import ( + "go.alanpearce.eu/searchix/internal/config" + "go.alanpearce.eu/searchix/internal/index" + "go.alanpearce.eu/searchix/internal/nix" + + g "go.alanpearce.eu/gomponents" + . "go.alanpearce.eu/gomponents/html" +) + +func CombinedData(data nix.Importable) g.Node { + switch data.(type) { + case nix.Option: + if o := convertMatch[nix.Option](data); o != nil { + return firstSentence(o.Description) + } + case nix.Package: + if p := convertMatch[nix.Package](data); p != nil { + return g.Text(firstSentence(p.Description)) + } + } + + return g.Text("") +} + +func Combined(result *index.Result) g.Node { + return Table( + THead( + Tr( + Th(Scope("col"), g.Text("Attribute")), + Th(Scope("col"), g.Text("Description")), + g.If(config.DevMode, + Th(Scope("col"), g.Text("Score")), + ), + ), + ), + TBody( + g.Map(result.Hits, func(hit index.DocumentMatch) g.Node { + return Tr( + Td( + openCombinedDialogLink(nix.GetKey(hit.Data)), + ), + Td( + CombinedData(hit.Data), + ), + g.If(config.DevMode, + Td( + Score(hit), + ), + ), + ) + }), + ), + ) +}