all repos — searchix @ 520dcca2755dbbab13ceebdc53d03beec8b94533

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

internal/components/combined.go (view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package components

import (
	"alin.ovh/searchix/internal/config"
	"alin.ovh/searchix/internal/index"
	"alin.ovh/searchix/internal/nix"

	g "alin.ovh/gomponents"
	. "alin.ovh/gomponents/html"
)

func CombinedData(data nix.Importable) g.Node {
	switch data := data.(type) {
	case *nix.Option:
		return firstSentence(data.Description)
	case *nix.Package:
		return g.Text(firstSentence(data.Description))
	}

	return g.Text("No description Available")
}

func Combined(result *index.Result) g.Node {
	return Table(
		THead(
			Tr(
				Th(Scope("col"), g.Text("Attribute")),
				Th(Scope("col"), Class("description"), g.Text("Description")),
				g.If(config.DevMode,
					Th(Scope("col"), Class("score"), g.Text("Score")),
				),
			),
		),
		TBody(
			g.MapIter(result.Hits, func(hit index.DocumentMatch) g.Node {
				return Tr(
					Td(
						openCombinedDialogLink(hit.ID),
					),
					Td(Class("description"),
						CombinedData(hit.Data),
					),
					g.If(config.DevMode,
						Td(Class("score"),
							Score(hit),
						),
					),
				)
			}),
		),
	)
}