aboutsummaryrefslogtreecommitdiffstats
path: root/web/command/html/home.go
blob: 6de30bd7c1f82478fc9187c43b28285f1033d7ce (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package html

import (
	"fmt"

	"github.com/LMBishop/scrapbook/pkg/index"
	"github.com/LMBishop/scrapbook/pkg/site"
	. "github.com/LMBishop/scrapbook/web/skeleton"
	. "maragu.dev/gomponents"
	. "maragu.dev/gomponents/html"
)

func HomePage(siteIndex *index.SiteIndex) Node {
	return Page("All sites",
		H1(Text("All sites")),

		Div(
			Class("table sites-table"),
			Group{
				Span(
					Class("header name"),
					Text("Site"),
				),
				Span(
					Class("header status"),
					Text("Status"),
				),
				Span(
					Class("header flags"),
					Text("Flags"),
				),
				Span(
					Class("header actions"),
					Text("Actions"),
				),
			},

			Map(siteIndex.GetSites(), func(site *site.Site) Node {
				status := site.EvaluateSiteStatus()
				good := false
				if status == "live" {
					good = true
				}
				return Group{
					Span(
						Class("name"),
						Span(Text(site.Name)),
						If(site.SiteConfig.Host == "", Span(Text("no host"))),
						If(site.SiteConfig.Host != "", Span(Text(fmt.Sprintf("on %s", site.SiteConfig.Host)))),
					),
					Span(
						If(good, Class("status text-good")),
						If(!good, Class("status text-bad")),
						Text(status),
					),
					Span(
						Class("flags"),
						Text(site.ConvertFlagsToString()),
					),
					Span(
						Class("actions"),
						NavButton("Details", fmt.Sprintf("/site/%s/", site.Name)),
					),
				}
			}),
		),

		If(len(siteIndex.GetSites()) == 0, Alert("There are no sites to display", "")),

		Div(
			Class("control-group group-right"),

			NavButton("Create new", "/create"),
		),
	)
}