mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-22 15:22:00 +08:00
Merge pull request #744 from tboerger/feature/breadcrumb
browse: Dropped LinkedPath and updated browse template
This commit is contained in:
commit
ac80f6edc3
|
@ -264,7 +264,6 @@ footer {
|
||||||
</g>
|
</g>
|
||||||
</g>
|
</g>
|
||||||
|
|
||||||
|
|
||||||
<!-- File -->
|
<!-- File -->
|
||||||
<linearGradient id="a">
|
<linearGradient id="a">
|
||||||
<stop stop-color="#cbcbcb" offset="0"/>
|
<stop stop-color="#cbcbcb" offset="0"/>
|
||||||
|
@ -300,10 +299,10 @@ footer {
|
||||||
</defs>
|
</defs>
|
||||||
</svg>
|
</svg>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<h1>{{.LinkedPath}}</h1>
|
<h1>
|
||||||
|
{{range $url, $name := .BreadcrumbMap}}<a href="{{$url}}">{{$name}}</a>{{if ne $url "/"}}/{{end}}{{end}}
|
||||||
|
</h1>
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
<div class="meta">
|
<div class="meta">
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -69,33 +68,6 @@ type Listing struct {
|
||||||
middleware.Context
|
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 += `<a href="/">/</a>`
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
result += fmt.Sprintf(`<a href="%s/">%s</a>/`, strings.Join(parts[:i+1], "/"), part)
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// BreadcrumbMap returns l.Path where every element is a map
|
// BreadcrumbMap returns l.Path where every element is a map
|
||||||
// of URLs and path segment names.
|
// of URLs and path segment names.
|
||||||
func (l Listing) BreadcrumbMap() map[string]string {
|
func (l Listing) BreadcrumbMap() map[string]string {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user