forked from tangled.org/core
Monorepo for Tangled — https://tangled.org

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

Changed files
+211 -76
appview
pages
templates
repo
state
+3
appview/pages/pages.go
···
"github.com/alecthomas/chroma/v2/lexers"
"github.com/alecthomas/chroma/v2/styles"
"github.com/bluesky-social/indigo/atproto/syntax"
+
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/microcosm-cc/bluemonday"
)
···
RepoInfo RepoInfo
Active string
TagMap map[string][]string
+
Tags []*types.TagReference
+
CommitsTrunc []*object.Commit
types.RepoIndexResponse
HTMLReadme template.HTML
Raw bool
+170 -75
appview/pages/templates/repo/index.html
···
{{ block "branchSelector" . }}{{ end }}
<div class="grid grid-cols-1 md:grid-cols-2 gap-2">
{{ block "fileTree" . }}{{ end }}
-
{{ block "commitLog" . }}{{ end }}
+
{{ block "rightInfo" . }}{{ end }}
</div>
</main>
{{ end }}
···
{{ end }}
</optgroup>
</select>
-
<a
-
href="/{{ .RepoInfo.FullName }}/commits/{{ .Ref | urlquery }}"
-
class="ml-2 no-underline flex items-center gap-2 text-sm uppercase font-bold dark:text-white"
-
>
-
{{ i "logs" "w-4 h-4" }}
-
{{ .TotalCommits }}
-
{{ if eq .TotalCommits 1 }}commit{{ else }}commits{{ end }}
-
</a>
</div>
{{ end }}
···
</div>
{{ end }}
-
{{ define "commitLog" }}
-
<div id="commit-log" class="hidden md:block md:col-span-1">
-
{{ range .Commits }}
-
<div class="relative px-2 pb-8">
-
<div id="commit-message">
-
{{ $messageParts := splitN .Message "\n\n" 2 }}
-
<div class="text-base cursor-pointer">
-
<div>
+
{{ define "rightInfo" }}
+
<div id="right-info" class="col-span-1">
+
<div id="commit-log" class="md:col-span-1">
+
<h2
+
class="flex text-gray-500 dark:text-gray-400 items-center gap-2 pb-4 pl-2"
+
>
+
{{ i "logs" "w-4 h-4" }}
+
commits
+
</h2>
+
{{ range .CommitsTrunc }}
+
<div class="relative px-2 pb-8">
+
<div id="commit-message">
+
{{ $messageParts := splitN .Message "\n\n" 2 }}
+
<div class="text-base cursor-pointer">
<div>
-
<a
-
href="/{{ $.RepoInfo.FullName }}/commit/{{ .Hash.String }}"
-
class="inline no-underline hover:underline dark:text-white"
-
>{{ index $messageParts 0 }}</a
-
>
+
<div>
+
<a
+
href="/{{ $.RepoInfo.FullName }}/commit/{{ .Hash.String }}"
+
class="inline no-underline hover:underline dark:text-white"
+
>{{ index $messageParts 0 }}</a
+
>
+
{{ if gt (len $messageParts) 1 }}
+
+
<button
+
class="py-1/2 px-1 bg-gray-200 hover:bg-gray-400 rounded dark:bg-gray-700 dark:hover:bg-gray-600"
+
hx-on:click="this.parentElement.nextElementSibling.classList.toggle('hidden')"
+
>
+
{{ i "ellipsis" "w-3 h-3" }}
+
</button>
+
{{ end }}
+
</div>
{{ if gt (len $messageParts) 1 }}
-
-
<button
-
class="py-1/2 px-1 bg-gray-200 hover:bg-gray-400 rounded dark:bg-gray-700 dark:hover:bg-gray-600"
-
hx-on:click="this.parentElement.nextElementSibling.classList.toggle('hidden')"
+
<p
+
class="hidden mt-1 text-sm cursor-text pb-2 dark:text-gray-300"
>
-
{{ i "ellipsis" "w-3 h-3" }}
-
</button>
+
{{ nl2br (index $messageParts 1) }}
+
</p>
{{ end }}
</div>
-
{{ if gt (len $messageParts) 1 }}
-
<p
-
class="hidden mt-1 text-sm cursor-text pb-2 dark:text-gray-300"
-
>
-
{{ nl2br (index $messageParts 1) }}
-
</p>
-
{{ end }}
</div>
</div>
-
</div>
-
<div class="text-xs text-gray-500 dark:text-gray-400">
-
<span class="font-mono">
-
<a
-
href="/{{ $.RepoInfo.FullName }}/commit/{{ .Hash.String }}"
-
class="text-gray-500 dark:text-gray-400 no-underline hover:underline"
-
>{{ slice .Hash.String 0 8 }}</a></span>
-
<span
-
class="mx-2 before:content-['·'] before:select-none"
-
></span>
-
<span>
-
{{ $didOrHandle := index $.EmailToDidOrHandle .Author.Email }}
-
<a
-
href="{{ if $didOrHandle }}
-
/{{ $didOrHandle }}
-
{{ else }}
-
mailto:{{ .Author.Email }}
-
{{ end }}"
-
class="text-gray-500 dark:text-gray-400 no-underline hover:underline"
-
>{{ if $didOrHandle }}
-
{{ $didOrHandle }}
-
{{ else }}
-
{{ .Author.Name }}
-
{{ end }}</a
+
<div class="text-xs text-gray-500 dark:text-gray-400">
+
<span class="font-mono">
+
<a
+
href="/{{ $.RepoInfo.FullName }}/commit/{{ .Hash.String }}"
+
class="text-gray-500 dark:text-gray-400 no-underline hover:underline"
+
>{{ slice .Hash.String 0 8 }}</a
+
></span
>
-
</span>
-
<div
-
class="inline-block px-1 select-none after:content-['·']"
-
></div>
-
<span>{{ timeFmt .Author.When }}</span>
-
{{ $tagsForCommit := index $.TagMap .Hash.String }}
-
{{ if gt (len $tagsForCommit) 0 }}
+
<span
+
class="mx-2 before:content-['·'] before:select-none"
+
></span>
+
<span>
+
{{ $didOrHandle := index $.EmailToDidOrHandle .Author.Email }}
+
<a
+
href="{{ if $didOrHandle }}
+
/{{ $didOrHandle }}
+
{{ else }}
+
mailto:{{ .Author.Email }}
+
{{ end }}"
+
class="text-gray-500 dark:text-gray-400 no-underline hover:underline"
+
>{{ if $didOrHandle }}
+
{{ $didOrHandle }}
+
{{ else }}
+
{{ .Author.Name }}
+
{{ end }}</a
+
>
+
</span>
<div
class="inline-block px-1 select-none after:content-['·']"
></div>
-
{{ end }}
-
{{ range $tagsForCommit }}
-
<span
-
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"
-
>
-
{{ . }}
-
</span>
-
{{ end }}
+
<span>{{ timeFmt .Author.When }}</span>
+
{{ $tagsForCommit := index $.TagMap .Hash.String }}
+
{{ if gt (len $tagsForCommit) 0 }}
+
<div
+
class="inline-block px-1 select-none after:content-['·']"
+
></div>
+
{{ end }}
+
{{ range $tagsForCommit }}
+
<span
+
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"
+
>
+
{{ . }}
+
</span>
+
{{ end }}
+
</div>
+
</div>
+
{{ end }}
+
{{ $more := sub .TotalCommits (len .CommitsTrunc) }}
+
{{ if gt $more 0 }}
+
<div
+
class="flex text-gray-500 dark:text-gray-400 mb-2 gap-1 justify-end items-center"
+
>
+
<a
+
href="/{{ .RepoInfo.FullName }}/commits/{{ .Ref | urlquery }}"
+
class="text-gray-500 dark:text-gray-400 text-sm"
+
>
+
&hellip; and {{ $more }} more
+
</a>
+
{{ i "arrow-right" "w-3 h-3" }}
</div>
+
{{ end }}
+
</div>
+
{{ if gt (len .Tags) 0 }}
+
<div
+
id="tags"
+
class="md:col-span-1 pt-4 border-t border-gray-200 dark:border-gray-700"
+
>
+
<h2
+
class="flex text-gray-500 dark:text-gray-400 items-center gap-2 pb-4 pl-2"
+
>
+
{{ i "tags" "w-4 h-4" }}
+
tags
+
</h2>
+
{{ range .Tags }}
+
<div class="relative px-2 pb-4">
+
<div class="text-base">
+
<div>
+
<a
+
href="/{{ $.RepoInfo.FullName }}/tree/{{ .Reference.Name | urlquery }}"
+
class="inline no-underline hover:underline dark:text-white"
+
>{{ .Reference.Name }}</a
+
>
+
{{ if gt (len .Message) 0 }}
+
{{ $messageParts := splitN .Message "\n\n" 2 }}
+
{{ $title := index $messageParts 0 }}
+
{{ $description := index $messageParts 1 }}
+
<span
+
class="text-sm text-gray-500 dark:text-gray-400 ml-2 truncate inline-block align-middle"
+
>{{ $title }}</span
+
>
+
{{ if gt (len $description) 1 }}
+
<button
+
class="py-1/2 px-1 bg-gray-200 hover:bg-gray-400 rounded dark:bg-gray-700 dark:hover:bg-gray-600"
+
hx-on:click="this.parentElement.nextElementSibling.classList.toggle('hidden')"
+
>
+
{{ i "ellipsis" "w-3 h-3" }}
+
</button>
+
{{ end }}
+
{{ end }}
+
</div>
+
{{ if gt (len .Message) 0 }}
+
{{ $messageParts := splitN .Message "\n\n" 2 }}
+
{{ $description := index $messageParts 1 }}
+
{{ if gt (len $description) 1 }}
+
<div
+
class="hidden mt-1 text-sm cursor-text pb-2 dark:text-gray-300"
+
>
+
{{ $description | markdown }}
+
</div>
+
{{ end }}
+
{{ end }}
+
<div
+
class="text-xs text-gray-500 dark:text-gray-400"
+
>
+
<span class="font-mono">
+
<a
+
href="/{{ $.RepoInfo.FullName }}/commit/{{ .Reference.Hash }}"
+
class="text-gray-500 dark:text-gray-400 no-underline hover:underline"
+
>{{ slice .Reference.Hash 0 8 }}</a
+
>
+
</span>
+
{{ with .Tag }}
+
<div
+
class="inline-block px-1 select-none after:content-['·']"
+
></div>
+
<time>{{ timeFmt .Tagger.When }}</time>
+
{{ end }}
+
</div>
+
</div>
+
</div>
+
{{ end }}
</div>
{{ end }}
</div>
···
{{ define "repoAfter" }}
{{- if .HTMLReadme }}
+
<div
+
class="mt-4 bg-white text-gray-600 dark:text-gray-400
+
px-6 py-3 prose dark:prose-invert
+
border-gray-200 dark:border-gray-700
+
text-sm border-b rounded-tl rounded-tr"
+
>
+
{{ .ReadmeFileName }}
+
</div>
<section
-
class="mt-4 p-6 rounded bg-white dark:bg-gray-800 dark:text-white w-full mx-auto overflow-auto {{ if not .Raw }}
+
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 }}
prose dark:prose-invert dark:[&_pre]:bg-gray-900
dark:[&_code]:text-gray-300 dark:[&_pre_code]:bg-gray-900
dark:[&_pre]:border dark:[&_pre]:border-gray-700
+10 -1
appview/state/repo.go
···
tagMap[hash] = append(tagMap[hash], branch.Name)
}
-
emails := uniqueEmails(result.Commits)
+
c, t := balanceTagsAndCommits(len(result.Commits), len(result.Tags), 10)
+
commits := result.Commits[:c]
+
tags := result.Tags[:t]
+
emails := uniqueEmails(commits)
+
+
for _, tag := range tags {
+
fmt.Printf("%#v\n\n", tag)
+
}
user := s.auth.GetUser(r)
s.pages.RepoIndexPage(w, pages.RepoIndexParams{
LoggedInUser: user,
RepoInfo: f.RepoInfo(s, user),
TagMap: tagMap,
+
Tags: tags,
RepoIndexResponse: result,
+
CommitsTrunc: commits,
EmailToDidOrHandle: EmailToDidOrHandle(s, emails),
})
return
+28
appview/state/repo_util.go
···
return uniqueEmails
}
+
func balanceTagsAndCommits(commits, tags, totalDesired int) (int, int) {
+
if commits == 0 && tags == 0 {
+
return 0, 0
+
}
+
+
half := totalDesired / 2
+
+
if commits+tags <= totalDesired {
+
return commits, tags
+
}
+
+
if commits >= half && tags >= half {
+
return half, half
+
}
+
+
if commits < half {
+
return commits, min(tags, totalDesired-commits)
+
}
+
+
if tags < half {
+
return min(commits, totalDesired-tags), tags
+
}
+
+
c := min(commits, half)
+
t := min(tags, totalDesired-c)
+
return c, t
+
}
+
func EmailToDidOrHandle(s *State, emails []string) map[string]string {
emailToDid, err := db.GetEmailToDid(s.db, emails, true) // only get verified emails for mapping
if err != nil {