Home

ugit @8445f0c8981c322218057d60e8662150ee3569a5 - refs - log -
-
https://git.jolheiser.com/ugit.git
The code powering this h*ckin' site
ugit / internal / html / repo_breadcrumb.templ
- raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package html

import (
	"fmt"
	"strings"
	"path"
)

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,
			href:  fmt.Sprintf("/%s/tree/%s/", r.Repo, r.Ref),
		},
	}
	for idx, part := range parts {
		breadcrumbs = append(breadcrumbs, breadcrumb{
			label: part,
			href:  path.Join(breadcrumbs[idx].href, part),
		})
	}
	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>
	}
}