breadcrumb.go 529 B

123456789101112131415161718192021222324252627282930313233
  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. for i := 0; i < len(parts); i++ {
  13. name := parts[i]
  14. if name == "" {
  15. name = "/"
  16. }
  17. crumb := Breadcrumb{
  18. Name: name,
  19. Link: "/" + util.Join(parts[0:i+1]...),
  20. }
  21. if !strings.HasSuffix(crumb.Link, "/") {
  22. crumb.Link += "/"
  23. }
  24. crumbs = append(crumbs, crumb)
  25. }
  26. return
  27. }