apps/kepler/app.go 2.6 K raw
1
package main
2
3
import (
4
	"embed"
5
	"html/template"
6
	"log/slog"
7
	"time"
8
)
9
10
//go:embed templates/*.html static/* static/fonts/*
11
var appFS embed.FS
12
13
type App struct {
14
	Log          *slog.Logger
15
	Templates    map[string]*template.Template
16
	RepoRoot     string
17
	SiteName     string
18
	BaseURL      string
19
	CloneBaseURL string
20
	CloneSSHHost string
21
}
22
23
type pageBase struct {
24
	SiteName string
25
	RepoName string
26
	BaseURL  string
27
}
28
29
type indexPageData struct {
30
	pageBase
31
	Repos []RepoSummary
32
}
33
34
type repoPageData struct {
35
	pageBase
36
	Repo          RepoSummary
37
	Ref           string
38
	ReadmeHTML    template.HTML
39
	HasReadme     bool
40
	Branches      []RefInfo
41
	Tags          []RefInfo
42
	Commits       []CommitInfo
43
	DefaultRef    string
44
	LatestCommit  CommitInfo
45
	HasLatest     bool
46
	Entries       []TreeEntry
47
	CloneHTTPSURL string
48
	CloneSSHURL   string
49
}
50
51
type treePageData struct {
52
	pageBase
53
	Repo        RepoSummary
54
	Ref         string
55
	DefaultRef  string
56
	Path        string
57
	Breadcrumbs []Breadcrumb
58
	Entries     []TreeEntry
59
}
60
61
type blobPageData struct {
62
	pageBase
63
	Repo            RepoSummary
64
	Ref             string
65
	DefaultRef      string
66
	Path            string
67
	Breadcrumbs     []Breadcrumb
68
	Binary          bool
69
	Size            int64
70
	HighlightedHTML template.HTML
71
}
72
73
type logPageData struct {
74
	pageBase
75
	Repo       RepoSummary
76
	Ref        string
77
	DefaultRef string
78
	Commits    []CommitInfo
79
	Page       int
80
	NextPage   int
81
	PrevPage   int
82
	HasNext    bool
83
	HasPrev    bool
84
}
85
86
type commitPageData struct {
87
	pageBase
88
	Repo       RepoSummary
89
	DefaultRef string
90
	Commit     CommitInfo
91
	Files      []FilePatch
92
	Stats      DiffStats
93
}
94
95
type refsPageData struct {
96
	pageBase
97
	Repo       RepoSummary
98
	DefaultRef string
99
	Branches   []RefInfo
100
	Tags       []RefInfo
101
}
102
103
type Breadcrumb struct {
104
	Name string
105
	Href string
106
}
107
108
type RepoSummary struct {
109
	Name        string
110
	Description string
111
	DefaultRef  string
112
	LastCommit  time.Time
113
}
114
115
type RefInfo struct {
116
	Name   string
117
	SHA    string
118
	Time   time.Time
119
	Author string
120
}
121
122
type CommitInfo struct {
123
	SHA       string
124
	ShortSHA  string
125
	Author    string
126
	Email     string
127
	When      time.Time
128
	Subject   string
129
	Body      string
130
	ParentSHA string
131
}
132
133
type TreeEntry struct {
134
	Name   string
135
	Path   string
136
	IsDir  bool
137
	Size   int64
138
	Mode   string
139
	Commit CommitInfo
140
}
141
142
type FilePatch struct {
143
	From    string
144
	To      string
145
	IsBin   bool
146
	Hunks   []DiffHunk
147
	Added   int
148
	Removed int
149
}
150
151
type DiffHunk struct {
152
	Header string
153
	Lines  []DiffLine
154
}
155
156
type DiffLine struct {
157
	Kind   string // "ctx", "add", "del"
158
	Text   string
159
	OldNum int
160
	NewNum int
161
}
162
163
type DiffStats struct {
164
	Files   int
165
	Added   int
166
	Removed int
167
}