Skip to content
This repository has been archived by the owner on May 22, 2020. It is now read-only.

Commit

Permalink
Merge pull request caddyserver#740 from tboerger/feature/browse-bread…
Browse files Browse the repository at this point in the history
…crumb

Added breadcrumb map function to browse
  • Loading branch information
Matt Holt committed Apr 11, 2016
2 parents 004a7f8 + e0b63d9 commit 36a3e20
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions middleware/browse/browse.go
Expand Up @@ -96,6 +96,34 @@ func (l Listing) LinkedPath() string {
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
type FileInfo struct {
IsDir bool
Expand Down

0 comments on commit 36a3e20

Please sign in to comment.