diff options
author | Alan Pearce | 2025-03-20 13:20:16 +0100 |
---|---|---|
committer | Alan Pearce | 2025-03-20 13:20:16 +0100 |
commit | 7247322a386f065c643dc58f0ae5b57ad7ec1cc1 (patch) | |
tree | 3941fe279ffb36e88f1527aecb2ac06f9fe9aecf /internal/components/search.go | |
parent | 2705e97ce1cf7d6a399c5f0175c36562fdef3352 (diff) | |
download | searchix-7247322a386f065c643dc58f0ae5b57ad7ec1cc1.tar.lz searchix-7247322a386f065c643dc58f0ae5b57ad7ec1cc1.tar.zst searchix-7247322a386f065c643dc58f0ae5b57ad7ec1cc1.zip |
feat: make list of source links dynamic
Diffstat (limited to 'internal/components/search.go')
-rw-r--r-- | internal/components/search.go | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/internal/components/search.go b/internal/components/search.go index b8803c8..b4ef7bd 100644 --- a/internal/components/search.go +++ b/internal/components/search.go @@ -5,6 +5,7 @@ import ( 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 @@ func SearchPage(tdata TemplateData, r ResultData, children ...g.Node) g.Node { 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 SearchPage(tdata TemplateData, r ResultData, children ...g.Node) g.Node { ), ) } + +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) +} |