mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-08 11:58:49 +03:00
Merge pull request #740 from tboerger/feature/browse-breadcrumb
Added breadcrumb map function to browse
This commit is contained in:
commit
36a3e204b6
1 changed files with 28 additions and 0 deletions
|
@ -96,6 +96,34 @@ func (l Listing) LinkedPath() string {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BreadcrumbMap returns l.Path where every element is a map
|
||||||
|
// of URLs and path segment names.
|
||||||
|
func (l Listing) BreadcrumbMap() map[string]string {
|
||||||
|
result := map[string]string{}
|
||||||
|
|
||||||
|
if len(l.Path) == 0 {
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// skip trailing slash
|
||||||
|
lpath := l.Path
|
||||||
|
if lpath[len(lpath)-1] == '/' {
|
||||||
|
lpath = lpath[:len(lpath)-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
parts := strings.Split(lpath, "/")
|
||||||
|
for i, part := range parts {
|
||||||
|
if i == 0 && part == "" {
|
||||||
|
// Leading slash (root)
|
||||||
|
result["/"] = "/"
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
result[strings.Join(parts[:i+1], "/")] = part
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// FileInfo is the info about a particular file or directory
|
// FileInfo is the info about a particular file or directory
|
||||||
type FileInfo struct {
|
type FileInfo struct {
|
||||||
IsDir bool
|
IsDir bool
|
||||||
|
|
Loading…
Reference in a new issue