You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
480 B

7 years ago
  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. }