+3
appview/pages/pages.go
+3
appview/pages/pages.go
···
30
30
"github.com/alecthomas/chroma/v2/lexers"
31
31
"github.com/alecthomas/chroma/v2/styles"
32
32
"github.com/bluesky-social/indigo/atproto/syntax"
33
+
"github.com/go-git/go-git/v5/plumbing/object"
33
34
"github.com/microcosm-cc/bluemonday"
34
35
)
35
36
···
462
463
RepoInfo RepoInfo
463
464
Active string
464
465
TagMap map[string][]string
466
+
Tags []*types.TagReference
467
+
CommitsTrunc []*object.Commit
465
468
types.RepoIndexResponse
466
469
HTMLReadme template.HTML
467
470
Raw bool
+170
-75
appview/pages/templates/repo/index.html
+170
-75
appview/pages/templates/repo/index.html
···
32
32
{{ block "branchSelector" . }}{{ end }}
33
33
<div class="grid grid-cols-1 md:grid-cols-2 gap-2">
34
34
{{ block "fileTree" . }}{{ end }}
35
-
{{ block "commitLog" . }}{{ end }}
35
+
{{ block "rightInfo" . }}{{ end }}
36
36
</div>
37
37
</main>
38
38
{{ end }}
···
72
72
{{ end }}
73
73
</optgroup>
74
74
</select>
75
-
<a
76
-
href="/{{ .RepoInfo.FullName }}/commits/{{ .Ref | urlquery }}"
77
-
class="ml-2 no-underline flex items-center gap-2 text-sm uppercase font-bold dark:text-white"
78
-
>
79
-
{{ i "logs" "w-4 h-4" }}
80
-
{{ .TotalCommits }}
81
-
{{ if eq .TotalCommits 1 }}commit{{ else }}commits{{ end }}
82
-
</a>
83
75
</div>
84
76
{{ end }}
85
77
···
136
128
</div>
137
129
{{ end }}
138
130
139
-
{{ define "commitLog" }}
140
-
<div id="commit-log" class="hidden md:block md:col-span-1">
141
-
{{ range .Commits }}
142
-
<div class="relative px-2 pb-8">
143
-
<div id="commit-message">
144
-
{{ $messageParts := splitN .Message "\n\n" 2 }}
145
-
<div class="text-base cursor-pointer">
146
-
<div>
131
+
{{ define "rightInfo" }}
132
+
<div id="right-info" class="col-span-1">
133
+
<div id="commit-log" class="md:col-span-1">
134
+
<h2
135
+
class="flex text-gray-500 dark:text-gray-400 items-center gap-2 pb-4 pl-2"
136
+
>
137
+
{{ i "logs" "w-4 h-4" }}
138
+
commits
139
+
</h2>
140
+
{{ range .CommitsTrunc }}
141
+
<div class="relative px-2 pb-8">
142
+
<div id="commit-message">
143
+
{{ $messageParts := splitN .Message "\n\n" 2 }}
144
+
<div class="text-base cursor-pointer">
147
145
<div>
148
-
<a
149
-
href="/{{ $.RepoInfo.FullName }}/commit/{{ .Hash.String }}"
150
-
class="inline no-underline hover:underline dark:text-white"
151
-
>{{ index $messageParts 0 }}</a
152
-
>
146
+
<div>
147
+
<a
148
+
href="/{{ $.RepoInfo.FullName }}/commit/{{ .Hash.String }}"
149
+
class="inline no-underline hover:underline dark:text-white"
150
+
>{{ index $messageParts 0 }}</a
151
+
>
152
+
{{ if gt (len $messageParts) 1 }}
153
+
154
+
<button
155
+
class="py-1/2 px-1 bg-gray-200 hover:bg-gray-400 rounded dark:bg-gray-700 dark:hover:bg-gray-600"
156
+
hx-on:click="this.parentElement.nextElementSibling.classList.toggle('hidden')"
157
+
>
158
+
{{ i "ellipsis" "w-3 h-3" }}
159
+
</button>
160
+
{{ end }}
161
+
</div>
153
162
{{ if gt (len $messageParts) 1 }}
154
-
155
-
<button
156
-
class="py-1/2 px-1 bg-gray-200 hover:bg-gray-400 rounded dark:bg-gray-700 dark:hover:bg-gray-600"
157
-
hx-on:click="this.parentElement.nextElementSibling.classList.toggle('hidden')"
163
+
<p
164
+
class="hidden mt-1 text-sm cursor-text pb-2 dark:text-gray-300"
158
165
>
159
-
{{ i "ellipsis" "w-3 h-3" }}
160
-
</button>
166
+
{{ nl2br (index $messageParts 1) }}
167
+
</p>
161
168
{{ end }}
162
169
</div>
163
-
{{ if gt (len $messageParts) 1 }}
164
-
<p
165
-
class="hidden mt-1 text-sm cursor-text pb-2 dark:text-gray-300"
166
-
>
167
-
{{ nl2br (index $messageParts 1) }}
168
-
</p>
169
-
{{ end }}
170
170
</div>
171
171
</div>
172
-
</div>
173
172
174
-
<div class="text-xs text-gray-500 dark:text-gray-400">
175
-
<span class="font-mono">
176
-
<a
177
-
href="/{{ $.RepoInfo.FullName }}/commit/{{ .Hash.String }}"
178
-
class="text-gray-500 dark:text-gray-400 no-underline hover:underline"
179
-
>{{ slice .Hash.String 0 8 }}</a></span>
180
-
<span
181
-
class="mx-2 before:content-['·'] before:select-none"
182
-
></span>
183
-
<span>
184
-
{{ $didOrHandle := index $.EmailToDidOrHandle .Author.Email }}
185
-
<a
186
-
href="{{ if $didOrHandle }}
187
-
/{{ $didOrHandle }}
188
-
{{ else }}
189
-
mailto:{{ .Author.Email }}
190
-
{{ end }}"
191
-
class="text-gray-500 dark:text-gray-400 no-underline hover:underline"
192
-
>{{ if $didOrHandle }}
193
-
{{ $didOrHandle }}
194
-
{{ else }}
195
-
{{ .Author.Name }}
196
-
{{ end }}</a
173
+
<div class="text-xs text-gray-500 dark:text-gray-400">
174
+
<span class="font-mono">
175
+
<a
176
+
href="/{{ $.RepoInfo.FullName }}/commit/{{ .Hash.String }}"
177
+
class="text-gray-500 dark:text-gray-400 no-underline hover:underline"
178
+
>{{ slice .Hash.String 0 8 }}</a
179
+
></span
197
180
>
198
-
</span>
199
-
<div
200
-
class="inline-block px-1 select-none after:content-['·']"
201
-
></div>
202
-
<span>{{ timeFmt .Author.When }}</span>
203
-
{{ $tagsForCommit := index $.TagMap .Hash.String }}
204
-
{{ if gt (len $tagsForCommit) 0 }}
181
+
<span
182
+
class="mx-2 before:content-['·'] before:select-none"
183
+
></span>
184
+
<span>
185
+
{{ $didOrHandle := index $.EmailToDidOrHandle .Author.Email }}
186
+
<a
187
+
href="{{ if $didOrHandle }}
188
+
/{{ $didOrHandle }}
189
+
{{ else }}
190
+
mailto:{{ .Author.Email }}
191
+
{{ end }}"
192
+
class="text-gray-500 dark:text-gray-400 no-underline hover:underline"
193
+
>{{ if $didOrHandle }}
194
+
{{ $didOrHandle }}
195
+
{{ else }}
196
+
{{ .Author.Name }}
197
+
{{ end }}</a
198
+
>
199
+
</span>
205
200
<div
206
201
class="inline-block px-1 select-none after:content-['·']"
207
202
></div>
208
-
{{ end }}
209
-
{{ range $tagsForCommit }}
210
-
<span
211
-
class="text-xs rounded bg-gray-100 dark:bg-gray-700 text-black dark:text-white font-mono px-2 mx-1/2 inline-flex items-center"
212
-
>
213
-
{{ . }}
214
-
</span>
215
-
{{ end }}
203
+
<span>{{ timeFmt .Author.When }}</span>
204
+
{{ $tagsForCommit := index $.TagMap .Hash.String }}
205
+
{{ if gt (len $tagsForCommit) 0 }}
206
+
<div
207
+
class="inline-block px-1 select-none after:content-['·']"
208
+
></div>
209
+
{{ end }}
210
+
{{ range $tagsForCommit }}
211
+
<span
212
+
class="text-xs rounded bg-gray-100 dark:bg-gray-700 text-black dark:text-white font-mono px-2 mx-1/2 inline-flex items-center"
213
+
>
214
+
{{ . }}
215
+
</span>
216
+
{{ end }}
217
+
</div>
218
+
</div>
219
+
{{ end }}
220
+
{{ $more := sub .TotalCommits (len .CommitsTrunc) }}
221
+
{{ if gt $more 0 }}
222
+
<div
223
+
class="flex text-gray-500 dark:text-gray-400 mb-2 gap-1 justify-end items-center"
224
+
>
225
+
<a
226
+
href="/{{ .RepoInfo.FullName }}/commits/{{ .Ref | urlquery }}"
227
+
class="text-gray-500 dark:text-gray-400 text-sm"
228
+
>
229
+
… and {{ $more }} more
230
+
</a>
231
+
{{ i "arrow-right" "w-3 h-3" }}
216
232
</div>
233
+
{{ end }}
234
+
</div>
235
+
{{ if gt (len .Tags) 0 }}
236
+
<div
237
+
id="tags"
238
+
class="md:col-span-1 pt-4 border-t border-gray-200 dark:border-gray-700"
239
+
>
240
+
<h2
241
+
class="flex text-gray-500 dark:text-gray-400 items-center gap-2 pb-4 pl-2"
242
+
>
243
+
{{ i "tags" "w-4 h-4" }}
244
+
tags
245
+
</h2>
246
+
{{ range .Tags }}
247
+
<div class="relative px-2 pb-4">
248
+
<div class="text-base">
249
+
<div>
250
+
<a
251
+
href="/{{ $.RepoInfo.FullName }}/tree/{{ .Reference.Name | urlquery }}"
252
+
class="inline no-underline hover:underline dark:text-white"
253
+
>{{ .Reference.Name }}</a
254
+
>
255
+
{{ if gt (len .Message) 0 }}
256
+
{{ $messageParts := splitN .Message "\n\n" 2 }}
257
+
{{ $title := index $messageParts 0 }}
258
+
{{ $description := index $messageParts 1 }}
259
+
<span
260
+
class="text-sm text-gray-500 dark:text-gray-400 ml-2 truncate inline-block align-middle"
261
+
>{{ $title }}</span
262
+
>
263
+
{{ if gt (len $description) 1 }}
264
+
<button
265
+
class="py-1/2 px-1 bg-gray-200 hover:bg-gray-400 rounded dark:bg-gray-700 dark:hover:bg-gray-600"
266
+
hx-on:click="this.parentElement.nextElementSibling.classList.toggle('hidden')"
267
+
>
268
+
{{ i "ellipsis" "w-3 h-3" }}
269
+
</button>
270
+
{{ end }}
271
+
{{ end }}
272
+
</div>
273
+
{{ if gt (len .Message) 0 }}
274
+
{{ $messageParts := splitN .Message "\n\n" 2 }}
275
+
{{ $description := index $messageParts 1 }}
276
+
{{ if gt (len $description) 1 }}
277
+
<div
278
+
class="hidden mt-1 text-sm cursor-text pb-2 dark:text-gray-300"
279
+
>
280
+
{{ $description | markdown }}
281
+
</div>
282
+
{{ end }}
283
+
{{ end }}
284
+
<div
285
+
class="text-xs text-gray-500 dark:text-gray-400"
286
+
>
287
+
<span class="font-mono">
288
+
<a
289
+
href="/{{ $.RepoInfo.FullName }}/commit/{{ .Reference.Hash }}"
290
+
class="text-gray-500 dark:text-gray-400 no-underline hover:underline"
291
+
>{{ slice .Reference.Hash 0 8 }}</a
292
+
>
293
+
</span>
294
+
{{ with .Tag }}
295
+
<div
296
+
class="inline-block px-1 select-none after:content-['·']"
297
+
></div>
298
+
<time>{{ timeFmt .Tagger.When }}</time>
299
+
{{ end }}
300
+
</div>
301
+
</div>
302
+
</div>
303
+
{{ end }}
217
304
</div>
218
305
{{ end }}
219
306
</div>
···
221
308
222
309
{{ define "repoAfter" }}
223
310
{{- if .HTMLReadme }}
311
+
<div
312
+
class="mt-4 bg-white text-gray-600 dark:text-gray-400
313
+
px-6 py-3 prose dark:prose-invert
314
+
border-gray-200 dark:border-gray-700
315
+
text-sm border-b rounded-tl rounded-tr"
316
+
>
317
+
{{ .ReadmeFileName }}
318
+
</div>
224
319
<section
225
-
class="mt-4 p-6 rounded bg-white dark:bg-gray-800 dark:text-white w-full mx-auto overflow-auto {{ if not .Raw }}
320
+
class="p-6 rounded-br rounded-bl bg-white dark:bg-gray-800 dark:text-white w-full mx-auto overflow-auto {{ if not .Raw }}
226
321
prose dark:prose-invert dark:[&_pre]:bg-gray-900
227
322
dark:[&_code]:text-gray-300 dark:[&_pre_code]:bg-gray-900
228
323
dark:[&_pre]:border dark:[&_pre]:border-gray-700
+10
-1
appview/state/repo.go
+10
-1
appview/state/repo.go
···
82
82
tagMap[hash] = append(tagMap[hash], branch.Name)
83
83
}
84
84
85
-
emails := uniqueEmails(result.Commits)
85
+
c, t := balanceTagsAndCommits(len(result.Commits), len(result.Tags), 10)
86
+
commits := result.Commits[:c]
87
+
tags := result.Tags[:t]
88
+
emails := uniqueEmails(commits)
89
+
90
+
for _, tag := range tags {
91
+
fmt.Printf("%#v\n\n", tag)
92
+
}
86
93
87
94
user := s.auth.GetUser(r)
88
95
s.pages.RepoIndexPage(w, pages.RepoIndexParams{
89
96
LoggedInUser: user,
90
97
RepoInfo: f.RepoInfo(s, user),
91
98
TagMap: tagMap,
99
+
Tags: tags,
92
100
RepoIndexResponse: result,
101
+
CommitsTrunc: commits,
93
102
EmailToDidOrHandle: EmailToDidOrHandle(s, emails),
94
103
})
95
104
return
+28
appview/state/repo_util.go
+28
appview/state/repo_util.go
···
82
82
return uniqueEmails
83
83
}
84
84
85
+
func balanceTagsAndCommits(commits, tags, totalDesired int) (int, int) {
86
+
if commits == 0 && tags == 0 {
87
+
return 0, 0
88
+
}
89
+
90
+
half := totalDesired / 2
91
+
92
+
if commits+tags <= totalDesired {
93
+
return commits, tags
94
+
}
95
+
96
+
if commits >= half && tags >= half {
97
+
return half, half
98
+
}
99
+
100
+
if commits < half {
101
+
return commits, min(tags, totalDesired-commits)
102
+
}
103
+
104
+
if tags < half {
105
+
return min(commits, totalDesired-tags), tags
106
+
}
107
+
108
+
c := min(commits, half)
109
+
t := min(tags, totalDesired-c)
110
+
return c, t
111
+
}
112
+
85
113
func EmailToDidOrHandle(s *State, emails []string) map[string]string {
86
114
emailToDid, err := db.GetEmailToDid(s.db, emails, true) // only get verified emails for mapping
87
115
if err != nil {