all repos — searchix @ 7247322a386f065c643dc58f0ae5b57ad7ec1cc1

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

feat: make list of source links dynamic

Alan Pearce
commit

7247322a386f065c643dc58f0ae5b57ad7ec1cc1

parent

2705e97ce1cf7d6a399c5f0175c36562fdef3352

1 file changed, 24 insertions(+), 5 deletions(-)

changed files
M internal/components/search.gointernal/components/search.go
@@ -5,6 +5,7 @@ "time"
g "go.alanpearce.eu/gomponents" . "go.alanpearce.eu/gomponents/html" + "go.alanpearce.eu/searchix/internal/config" ) func SearchForm(tdata TemplateData, r ResultData) g.Node {
@@ -35,11 +36,9 @@ return Page(
tdata, P( g.Text("Search Nix packages and options from "), - A(Href("https://nixos.org"), g.Text("NixOS")), - g.Text(", "), - A(Href("https://github.com/LnL7/nix-darwin"), g.Text("nix-darwin")), - g.Text(" and "), - A(Href("https://github.com/nix-community/home-manager"), g.Text("home-manager")), + MapCommaList(tdata.Sources, func(source *config.Source) g.Node { + return A(Href(source.Repo.String()), g.Text(source.Name)) + }), ), g.If(Indexing.InProgress, P(Class("notice"),
@@ -96,3 +95,23 @@ ),
), ) } + +func MapCommaList[T any](items []T, fn func(T) g.Node) g.Node { + out := make([]g.Node, (len(items) * 2)) + j := 0 + last := len(items) - 2 + for i := range items { + out[j] = fn(items[i]) + j++ + if i <= last { + if i == last { + out[j] = g.Text(" and ") + } else { + out[j] = g.Text(", ") + } + } + j++ + } + + return g.Group(out) +}