Home

ugit @main - refs - log -
-
https://git.jolheiser.com/ugit.git
The code powering this h*ckin' site
ugit / internal / html / repo_commit.go
- 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
53
54
55
56
57
58
59
60
61
62
63
64
65
package html

import (
	"fmt"

	"github.com/dustin/go-humanize"
	"go.jolheiser.com/ugit/internal/git"
	. "maragu.dev/gomponents"
	. "maragu.dev/gomponents/html"
)

type RepoCommitContext struct {
	BaseContext
	RepoHeaderComponentContext
	Commit git.Commit
}

func RepoCommitTemplate(rcc RepoCommitContext) Node {
	return base(rcc.BaseContext, []Node{
		repoHeaderComponent(rcc.RepoHeaderComponentContext),
		Div(Class("text-text mt-5"),
			A(Class("underline decoration-text/50 decoration-dashed hover:decoration-solid"), Href(fmt.Sprintf("/%s/tree/%s/", rcc.RepoHeaderComponentContext.Name, rcc.Commit.SHA)), Text("tree")),
			Text(" "),
			A(Class("underline decoration-text/50 decoration-dashed hover:decoration-solid"), Href(fmt.Sprintf("/%s/log/%s", rcc.RepoHeaderComponentContext.Name, rcc.Commit.SHA)), Text("log")),
			Text(" "),
			A(Class("underline decoration-text/50 decoration-dashed hover:decoration-solid"), Href(fmt.Sprintf("/%s/commit/%s.patch", rcc.RepoHeaderComponentContext.Name, rcc.Commit.SHA)), Text("patch")),
		),
		Div(Class("text-text whitespace-pre mt-5 p-3 bg-base rounded"), Text(rcc.Commit.Message)),
		If(rcc.Commit.Signature != "",
			Details(Class("text-text whitespace-pre"),
				Summary(Class("cursor-pointer"), Text("Signature")),
				Div(Class("p-3 bg-base rounded"),
					Code(Text(rcc.Commit.Signature)),
				),
			),
		),
		Div(Class("text-text mt-3"),
			Div(
				Text(rcc.Commit.Author),
				Text(" "),
				A(Class("underline decoration-text/50 decoration-dashed hover:decoration-solid"), Href(fmt.Sprintf("mailto:%s", rcc.Commit.Email)), Text(fmt.Sprintf("<%s>", rcc.Commit.Email))),
			),
			Div(Title(rcc.Commit.When.Format("01/02/2006 03:04:05 PM")), Text(humanize.Time(rcc.Commit.When))),
		),
		Div(Class("text-text mt-5"), Textf("%d changed files, %d additions(+), %d deletions(-)", rcc.Commit.Stats.Changed, rcc.Commit.Stats.Additions, rcc.Commit.Stats.Deletions)),
		Map(rcc.Commit.Files, func(file git.CommitFile) Node {
			return Group([]Node{
				Div(Class("text-text mt-5"),
					Span(Class("text-text/80"), Title(file.Action), Text(string(file.Action[0]))),
					Text(" "),
					If(file.From.Path != "",
						A(Class("underline decoration-text/50 decoration-dashed hover:decoration-solid"), Href(fmt.Sprintf("/%s/tree/%s/%s", rcc.RepoHeaderComponentContext.Name, file.From.Commit, file.From.Path)), Text(file.From.Path)),
					),
					If(file.From.Path != file.To.Path, Text(" → ")),
					If(file.To.Path != "",
						A(Class("underline decoration-text/50 decoration-dashed hover:decoration-solid"), Href(fmt.Sprintf("/%s/tree/%s/%s", rcc.RepoHeaderComponentContext.Name, file.To.Commit, file.To.Path)), Text(file.To.Path)),
					),
				),
				Div(Class("whitespace-pre code"),
					Raw(file.Patch),
				),
			})
		}),
	}...)
}