2024-06-27 04:23:41 +00:00
|
|
|
package html
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
2024-07-09 20:54:04 +00:00
|
|
|
"path"
|
2024-06-27 04:23:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type RepoBreadcrumbComponentContext struct {
|
|
|
|
Repo string
|
|
|
|
Ref string
|
|
|
|
Path string
|
|
|
|
}
|
|
|
|
|
|
|
|
type breadcrumb struct {
|
|
|
|
label string
|
|
|
|
href string
|
|
|
|
end bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r RepoBreadcrumbComponentContext) crumbs() []breadcrumb {
|
|
|
|
parts := strings.Split(r.Path, "/")
|
|
|
|
breadcrumbs := []breadcrumb{
|
|
|
|
{
|
|
|
|
label: r.Repo,
|
2024-07-09 20:54:04 +00:00
|
|
|
href: fmt.Sprintf("/%s/tree/%s/", r.Repo, r.Ref),
|
2024-06-27 04:23:41 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for idx, part := range parts {
|
|
|
|
breadcrumbs = append(breadcrumbs, breadcrumb{
|
|
|
|
label: part,
|
2024-07-09 20:54:04 +00:00
|
|
|
href: path.Join(breadcrumbs[idx].href, part),
|
2024-06-27 04:23:41 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
breadcrumbs[len(breadcrumbs)-1].end = true
|
|
|
|
return breadcrumbs
|
|
|
|
}
|
|
|
|
|
|
|
|
templ repoBreadcrumbComponent(rbcc RepoBreadcrumbComponentContext) {
|
|
|
|
if rbcc.Path != "" {
|
|
|
|
<div class="inline-block text-text">
|
|
|
|
for _, crumb := range rbcc.crumbs() {
|
|
|
|
if crumb.end {
|
|
|
|
<span>{ crumb.label }</span>
|
|
|
|
} else {
|
|
|
|
<a class="underline decoration-text/50 decoration-dashed hover:decoration-solid" href={ templ.SafeURL(crumb.href) }>{ crumb.label }</a>
|
|
|
|
{ " / " }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|