breadcrumb.go 480 B

12345678910111213141516171819202122232425262728
  1. package master_ui
  2. import (
  3. "path/filepath"
  4. "strings"
  5. )
  6. type Breadcrumb struct {
  7. Name string
  8. Link string
  9. }
  10. func ToBreadcrumb(fullpath string) (crumbs []Breadcrumb) {
  11. parts := strings.Split(fullpath, "/")
  12. for i := 0; i < len(parts); i++ {
  13. crumb := Breadcrumb{
  14. Name: parts[i] + " /",
  15. Link: "/" + filepath.ToSlash(filepath.Join(parts[0:i+1]...)),
  16. }
  17. if !strings.HasSuffix(crumb.Link, "/") {
  18. crumb.Link += "/"
  19. }
  20. crumbs = append(crumbs, crumb)
  21. }
  22. return
  23. }