breadcrumb.go 486 B

1234567891011121314151617181920212223242526272829
  1. package master_ui
  2. import (
  3. "strings"
  4. "github.com/chrislusf/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. crumb := Breadcrumb{
  14. Name: parts[i] + " /",
  15. Link: "/" + util.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. }