ugit/internal/html/index.templ

72 lines
2.2 KiB
Plaintext

package html
import "go.jolheiser.com/ugit/internal/git"
import "github.com/dustin/go-humanize"
import "go.jolheiser.com/ugit/assets"
type IndexContext struct {
BaseContext
Profile IndexProfile
Repos []*git.Repo
}
type IndexProfile struct {
Username string
Email string
Links []IndexLink
}
type IndexLink struct {
Name string
URL string
}
func lastCommit(repo *git.Repo, human bool) string {
c, err := repo.LastCommit()
if err != nil {
return ""
}
if human {
return humanize.Time(c.When)
}
return c.When.Format("01/02/2006 03:04:05 PM")
}
templ Index(ic IndexContext) {
@base(ic.BaseContext) {
<header>
<h1 class="text-text text-xl font-bold">{ ic.Title }</h1>
<h2 class="text-subtext1 text-lg">{ ic.Description }</h2>
</header>
<main class="mt-5">
<div class="grid grid-cols-1 sm:grid-cols-8">
if ic.Profile.Username != "" {
<div class="text-mauve">{ `@` + ic.Profile.Username }</div>
}
if ic.Profile.Email != "" {
<div class="text-mauve col-span-2">
<div class="w-5 h-5 stroke-mauve inline-block mr-1 align-middle">@templ.Raw(string(assets.EmailIcon))</div>
<a class="underline decoration-mauve/50 decoration-dashed hover:decoration-solid" href={ templ.SafeURL("mailto:" + ic.Profile.Email) }>{ ic.Profile.Email }</a>
</div>
}
</div>
<div class="grid grid-cols-1 sm:grid-cols-8">
for _, link := range ic.Profile.Links {
<div class="text-mauve">
<div class="w-5 h-5 stroke-mauve inline-block mr-1 align-middle">@templ.Raw(string(assets.LinkIcon))</div>
<a class="underline decoration-mauve/50 decoration-dashed hover:decoration-solid" rel="me" href={ templ.SafeURL(link.URL) }>{ link.Name }</a>
</div>
}
</div>
<div class="grid sm:grid-cols-8 gap-1 mt-5">
for _, repo := range ic.Repos {
<div class="sm:col-span-1 text-blue dark:text-lavender"><a class="underline decoration-blue/50 dark:decoration-lavender/50 decoration-dashed hover:decoration-solid" href={ templ.URL("/" + repo.Name()) }>{ repo.Name() }</a></div>
<div class="sm:col-span-5 text-subtext0">{ repo.Meta.Description }</div>
<div class="sm:col-span-2 text-text/80 mb-4 sm:mb-0" title={ lastCommit(repo, false) }>{ lastCommit(repo, true) }</div>
}
</div>
</main>
}
}