breadcrumb.go 577 B

123456789101112131415161718192021222324252627282930313233343536
  1. package filer_ui
  2. import (
  3. "strings"
  4. "github.com/seaweedfs/seaweedfs/weed/util"
  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. if fullpath == "/" {
  13. parts = []string{""}
  14. }
  15. for i := 0; i < len(parts); i++ {
  16. name := parts[i]
  17. if name == "" {
  18. name = "/"
  19. }
  20. crumb := Breadcrumb{
  21. Name: name,
  22. Link: "/" + util.Join(parts[0:i+1]...),
  23. }
  24. if !strings.HasSuffix(crumb.Link, "/") {
  25. crumb.Link += "/"
  26. }
  27. crumbs = append(crumbs, crumb)
  28. }
  29. return
  30. }