about summary refs log tree commit diff stats
path: root/internal/components/search.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/components/search.go')
-rw-r--r--internal/components/search.go29
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)
+}