seaweedfs/weed/server/filer_ui/breadcrumb.go

34 lines
529 B
Go
Raw Normal View History

2021-04-23 05:21:11 +08:00
package filer_ui
2018-05-25 14:42:13 +08:00
import (
2018-05-28 02:52:26 +08:00
"strings"
2020-04-06 04:11:43 +08:00
"github.com/seaweedfs/seaweedfs/weed/util"
2018-05-25 14:42:13 +08:00
)
type Breadcrumb struct {
Name string
Link string
}
func ToBreadcrumb(fullpath string) (crumbs []Breadcrumb) {
parts := strings.Split(fullpath, "/")
for i := 0; i < len(parts); i++ {
2022-04-07 17:53:22 +08:00
name := parts[i]
if name == "" {
name = "/"
}
2019-12-12 15:09:01 +08:00
crumb := Breadcrumb{
2022-04-07 17:53:22 +08:00
Name: name,
2020-04-06 04:11:43 +08:00
Link: "/" + util.Join(parts[0:i+1]...),
2019-12-12 15:09:01 +08:00
}
if !strings.HasSuffix(crumb.Link, "/") {
crumb.Link += "/"
}
crumbs = append(crumbs, crumb)
2018-05-25 14:42:13 +08:00
}
return
}