Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview: pages/templates: show tags and branches in repo index

authored by

Anirudh Oppiliappan and committed by
Akshay
0a852b61 8bed72cd

+212 -77
+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 ··· 463 462 RepoInfo RepoInfo 464 463 Active string 465 464 TagMap map[string][]string 465 + Tags []*types.TagReference 466 + CommitsTrunc []*object.Commit 466 467 types.RepoIndexResponse 467 468 HTMLReadme template.HTML 468 469 Raw bool
+171 -76
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 ··· 128 136 </div> 129 137 {{ end }} 130 138 131 - {{ define "commitLog" }} 132 - <div id="commit-log" class="hidden md:block md:col-span-1"> 133 - {{ range .Commits }} 134 - <div class="relative px-2 pb-8"> 135 - <div id="commit-message"> 136 - {{ $messageParts := splitN .Message "\n\n" 2 }} 137 - <div class="text-base cursor-pointer"> 138 - <div> 139 + {{ define "rightInfo" }} 140 + <div id="right-info" class="col-span-1"> 141 + <div id="commit-log" class="md:col-span-1"> 142 + <h2 143 + class="flex text-gray-500 dark:text-gray-400 items-center gap-2 pb-4 pl-2" 144 + > 145 + {{ i "logs" "w-4 h-4" }} 146 + commits 147 + </h2> 148 + {{ range .CommitsTrunc }} 149 + <div class="relative px-2 pb-8"> 150 + <div id="commit-message"> 151 + {{ $messageParts := splitN .Message "\n\n" 2 }} 152 + <div class="text-base cursor-pointer"> 139 153 <div> 140 - <a 141 - href="/{{ $.RepoInfo.FullName }}/commit/{{ .Hash.String }}" 142 - class="inline no-underline hover:underline dark:text-white" 143 - >{{ index $messageParts 0 }}</a 144 - > 145 - {{ if gt (len $messageParts) 1 }} 146 - 147 - <button 148 - class="py-1/2 px-1 bg-gray-200 hover:bg-gray-400 rounded dark:bg-gray-700 dark:hover:bg-gray-600" 149 - hx-on:click="this.parentElement.nextElementSibling.classList.toggle('hidden')" 154 + <div> 155 + <a 156 + href="/{{ $.RepoInfo.FullName }}/commit/{{ .Hash.String }}" 157 + class="inline no-underline hover:underline dark:text-white" 158 + >{{ index $messageParts 0 }}</a 150 159 > 151 - {{ i "ellipsis" "w-3 h-3" }} 152 - </button> 160 + {{ if gt (len $messageParts) 1 }} 161 + 162 + <button 163 + class="py-1/2 px-1 bg-gray-200 hover:bg-gray-400 rounded dark:bg-gray-700 dark:hover:bg-gray-600" 164 + hx-on:click="this.parentElement.nextElementSibling.classList.toggle('hidden')" 165 + > 166 + {{ i "ellipsis" "w-3 h-3" }} 167 + </button> 168 + {{ end }} 169 + </div> 170 + {{ if gt (len $messageParts) 1 }} 171 + <p 172 + class="hidden mt-1 text-sm cursor-text pb-2 dark:text-gray-300" 173 + > 174 + {{ nl2br (index $messageParts 1) }} 175 + </p> 153 176 {{ end }} 154 177 </div> 155 - {{ if gt (len $messageParts) 1 }} 156 - <p 157 - class="hidden mt-1 text-sm cursor-text pb-2 dark:text-gray-300" 158 - > 159 - {{ nl2br (index $messageParts 1) }} 160 - </p> 161 - {{ end }} 162 178 </div> 163 179 </div> 164 - </div> 165 180 166 - <div class="text-xs text-gray-500 dark:text-gray-400"> 167 - <span class="font-mono"> 168 - <a 169 - href="/{{ $.RepoInfo.FullName }}/commit/{{ .Hash.String }}" 170 - class="text-gray-500 dark:text-gray-400 no-underline hover:underline" 171 - >{{ slice .Hash.String 0 8 }}</a></span> 172 - <span 173 - class="mx-2 before:content-['·'] before:select-none" 174 - ></span> 175 - <span> 176 - {{ $didOrHandle := index $.EmailToDidOrHandle .Author.Email }} 177 - <a 178 - href="{{ if $didOrHandle }} 179 - /{{ $didOrHandle }} 180 - {{ else }} 181 - mailto:{{ .Author.Email }} 182 - {{ end }}" 183 - class="text-gray-500 dark:text-gray-400 no-underline hover:underline" 184 - >{{ if $didOrHandle }} 185 - {{ $didOrHandle }} 186 - {{ else }} 187 - {{ .Author.Name }} 188 - {{ end }}</a 181 + <div class="text-xs text-gray-500 dark:text-gray-400"> 182 + <span class="font-mono"> 183 + <a 184 + href="/{{ $.RepoInfo.FullName }}/commit/{{ .Hash.String }}" 185 + class="text-gray-500 dark:text-gray-400 no-underline hover:underline" 186 + >{{ slice .Hash.String 0 8 }}</a 187 + ></span 189 188 > 190 - </span> 191 - <div 192 - class="inline-block px-1 select-none after:content-['·']" 193 - ></div> 194 - <span>{{ timeFmt .Author.When }}</span> 195 - {{ $tagsForCommit := index $.TagMap .Hash.String }} 196 - {{ if gt (len $tagsForCommit) 0 }} 189 + <span 190 + class="mx-2 before:content-['·'] before:select-none" 191 + ></span> 192 + <span> 193 + {{ $didOrHandle := index $.EmailToDidOrHandle .Author.Email }} 194 + <a 195 + href="{{ if $didOrHandle }} 196 + /{{ $didOrHandle }} 197 + {{ else }} 198 + mailto:{{ .Author.Email }} 199 + {{ end }}" 200 + class="text-gray-500 dark:text-gray-400 no-underline hover:underline" 201 + >{{ if $didOrHandle }} 202 + {{ $didOrHandle }} 203 + {{ else }} 204 + {{ .Author.Name }} 205 + {{ end }}</a 206 + > 207 + </span> 197 208 <div 198 209 class="inline-block px-1 select-none after:content-['·']" 199 210 ></div> 200 - {{ end }} 201 - {{ range $tagsForCommit }} 202 - <span 203 - 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" 204 - > 205 - {{ . }} 206 - </span> 207 - {{ end }} 211 + <span>{{ timeFmt .Author.When }}</span> 212 + {{ $tagsForCommit := index $.TagMap .Hash.String }} 213 + {{ if gt (len $tagsForCommit) 0 }} 214 + <div 215 + class="inline-block px-1 select-none after:content-['·']" 216 + ></div> 217 + {{ end }} 218 + {{ range $tagsForCommit }} 219 + <span 220 + 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" 221 + > 222 + {{ . }} 223 + </span> 224 + {{ end }} 225 + </div> 208 226 </div> 227 + {{ end }} 228 + {{ $more := sub .TotalCommits (len .CommitsTrunc) }} 229 + {{ if gt $more 0 }} 230 + <div 231 + class="flex text-gray-500 dark:text-gray-400 mb-2 gap-1 justify-end items-center" 232 + > 233 + <a 234 + href="/{{ .RepoInfo.FullName }}/commits/{{ .Ref | urlquery }}" 235 + class="text-gray-500 dark:text-gray-400 text-sm" 236 + > 237 + &hellip; and {{ $more }} more 238 + </a> 239 + {{ i "arrow-right" "w-3 h-3" }} 240 + </div> 241 + {{ end }} 242 + </div> 243 + {{ if gt (len .Tags) 0 }} 244 + <div 245 + id="tags" 246 + class="md:col-span-1 pt-4 border-t border-gray-200 dark:border-gray-700" 247 + > 248 + <h2 249 + class="flex text-gray-500 dark:text-gray-400 items-center gap-2 pb-4 pl-2" 250 + > 251 + {{ i "tags" "w-4 h-4" }} 252 + tags 253 + </h2> 254 + {{ range .Tags }} 255 + <div class="relative px-2 pb-4"> 256 + <div class="text-base"> 257 + <div> 258 + <a 259 + href="/{{ $.RepoInfo.FullName }}/tree/{{ .Reference.Name | urlquery }}" 260 + class="inline no-underline hover:underline dark:text-white" 261 + >{{ .Reference.Name }}</a 262 + > 263 + {{ if gt (len .Message) 0 }} 264 + {{ $messageParts := splitN .Message "\n\n" 2 }} 265 + {{ $title := index $messageParts 0 }} 266 + {{ $description := index $messageParts 1 }} 267 + <span 268 + class="text-sm text-gray-500 dark:text-gray-400 ml-2 truncate inline-block align-middle" 269 + >{{ $title }}</span 270 + > 271 + {{ if gt (len $description) 1 }} 272 + <button 273 + class="py-1/2 px-1 bg-gray-200 hover:bg-gray-400 rounded dark:bg-gray-700 dark:hover:bg-gray-600" 274 + hx-on:click="this.parentElement.nextElementSibling.classList.toggle('hidden')" 275 + > 276 + {{ i "ellipsis" "w-3 h-3" }} 277 + </button> 278 + {{ end }} 279 + {{ end }} 280 + </div> 281 + {{ if gt (len .Message) 0 }} 282 + {{ $messageParts := splitN .Message "\n\n" 2 }} 283 + {{ $description := index $messageParts 1 }} 284 + {{ if gt (len $description) 1 }} 285 + <div 286 + class="hidden mt-1 text-sm cursor-text pb-2 dark:text-gray-300" 287 + > 288 + {{ $description | markdown }} 289 + </div> 290 + {{ end }} 291 + {{ end }} 292 + <div 293 + class="text-xs text-gray-500 dark:text-gray-400" 294 + > 295 + <span class="font-mono"> 296 + <a 297 + href="/{{ $.RepoInfo.FullName }}/commit/{{ .Reference.Hash }}" 298 + class="text-gray-500 dark:text-gray-400 no-underline hover:underline" 299 + >{{ slice .Reference.Hash 0 8 }}</a 300 + > 301 + </span> 302 + {{ with .Tag }} 303 + <div 304 + class="inline-block px-1 select-none after:content-['·']" 305 + ></div> 306 + <time>{{ timeFmt .Tagger.When }}</time> 307 + {{ end }} 308 + </div> 309 + </div> 310 + </div> 311 + {{ end }} 209 312 </div> 210 313 {{ end }} 211 314 </div> ··· 308 221 309 222 {{ define "repoAfter" }} 310 223 {{- if .HTMLReadme }} 224 + <div 225 + class="mt-4 bg-white text-gray-600 dark:text-gray-400 226 + px-6 py-3 prose dark:prose-invert 227 + border-gray-200 dark:border-gray-700 228 + text-sm border-b rounded-tl rounded-tr" 229 + > 230 + {{ .ReadmeFileName }} 231 + </div> 311 232 <section 312 - class="mt-4 p-6 rounded bg-white dark:bg-gray-800 dark:text-white w-full mx-auto overflow-auto {{ if not .Raw }} 233 + 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 }} 313 234 prose dark:prose-invert dark:[&_pre]:bg-gray-900 314 235 dark:[&_code]:text-gray-300 dark:[&_pre_code]:bg-gray-900 315 236 dark:[&_pre]:border dark:[&_pre]:border-gray-700
+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
··· 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 {