From ef95173827822ca58bbc82cdd9662a28bfddf065 Mon Sep 17 00:00:00 2001 From: Thomas Boerger Date: Tue, 12 Apr 2016 17:08:38 +0200 Subject: [PATCH] Dropped LinkedPath and updated browse template As discussed with @mholt I have dropped the old LinkedPath function and replaced it within the browse template with the new BreadcrumbMap function. Visually it looks exactly the same as before, now the template functionality is just more powerful. Signed-off-by: Thomas Boerger --- caddy/setup/browse.go | 9 ++++----- middleware/browse/browse.go | 28 ---------------------------- 2 files changed, 4 insertions(+), 33 deletions(-) diff --git a/caddy/setup/browse.go b/caddy/setup/browse.go index 63acaddd..28cb2582 100644 --- a/caddy/setup/browse.go +++ b/caddy/setup/browse.go @@ -264,7 +264,6 @@ footer { - @@ -300,14 +299,14 @@ footer { - -
-

{{.LinkedPath}}

+

+ {{range $url, $name := .BreadcrumbMap}}{{$name}}{{if ne $url "/"}}/{{end}}{{end}} +

-
+
{{.NumDirs}} director{{if eq 1 .NumDirs}}y{{else}}ies{{end}} {{.NumFiles}} file{{if ne 1 .NumFiles}}s{{end}}
diff --git a/middleware/browse/browse.go b/middleware/browse/browse.go index e6070079..6fe37ea3 100644 --- a/middleware/browse/browse.go +++ b/middleware/browse/browse.go @@ -6,7 +6,6 @@ import ( "bytes" "encoding/json" "errors" - "fmt" "net/http" "net/url" "os" @@ -69,33 +68,6 @@ type Listing struct { middleware.Context } -// LinkedPath returns l.Path where every element is a clickable -// link to the path up to that point so far. -func (l Listing) LinkedPath() string { - if len(l.Path) == 0 { - return "" - } - - // skip trailing slash - lpath := l.Path - if lpath[len(lpath)-1] == '/' { - lpath = lpath[:len(lpath)-1] - } - - parts := strings.Split(lpath, "/") - var result string - for i, part := range parts { - if i == 0 && part == "" { - // Leading slash (root) - result += `/` - continue - } - result += fmt.Sprintf(`%s/`, strings.Join(parts[:i+1], "/"), part) - } - - 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 {