Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
3ca419e2
Commit
3ca419e2
authored
Apr 14, 2017
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
browse: Correct links when site defined with a path (fixes #1561)
parent
7d154353
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
14 deletions
+18
-14
caddyhttp/browse/browse.go
caddyhttp/browse/browse.go
+17
-13
caddyhttp/browse/setup.go
caddyhttp/browse/setup.go
+1
-1
No files found.
caddyhttp/browse/browse.go
View file @
3ca419e2
...
@@ -37,7 +37,7 @@ type Browse struct {
...
@@ -37,7 +37,7 @@ type Browse struct {
// Config is a configuration for browsing in a particular path.
// Config is a configuration for browsing in a particular path.
type
Config
struct
{
type
Config
struct
{
PathScope
string
PathScope
string
// the base path the URL must match to enable browsing
Fs
staticfiles
.
FileServer
Fs
staticfiles
.
FileServer
Variables
interface
{}
Variables
interface
{}
Template
*
template
.
Template
Template
*
template
.
Template
...
@@ -78,10 +78,15 @@ type Listing struct {
...
@@ -78,10 +78,15 @@ type Listing struct {
httpserver
.
Context
httpserver
.
Context
}
}
// BreadcrumbMap returns l.Path where every element is a map
// Crumb represents part of a breadcrumb menu.
// of URLs and path segment names.
type
Crumb
struct
{
func
(
l
Listing
)
BreadcrumbMap
()
map
[
string
]
string
{
Link
,
Text
string
result
:=
map
[
string
]
string
{}
}
// Breadcrumbs returns l.Path where every element maps
// the link to the text to display.
func
(
l
Listing
)
Breadcrumbs
()
[]
Crumb
{
var
result
[]
Crumb
if
len
(
l
.
Path
)
==
0
{
if
len
(
l
.
Path
)
==
0
{
return
result
return
result
...
@@ -94,13 +99,12 @@ func (l Listing) BreadcrumbMap() map[string]string {
...
@@ -94,13 +99,12 @@ func (l Listing) BreadcrumbMap() map[string]string {
}
}
parts
:=
strings
.
Split
(
lpath
,
"/"
)
parts
:=
strings
.
Split
(
lpath
,
"/"
)
for
i
,
part
:=
range
parts
{
for
i
:=
range
parts
{
if
i
==
0
&&
part
==
""
{
txt
:=
parts
[
i
]
// Leading slash (root)
if
i
==
0
&&
parts
[
i
]
==
""
{
result
[
"/"
]
=
"/"
txt
=
"/"
continue
}
}
result
[
strings
.
Join
(
parts
[
:
i
+
1
],
"/"
)]
=
part
result
=
append
(
result
,
Crumb
{
Link
:
strings
.
Repeat
(
"../"
,
len
(
parts
)
-
i
-
1
),
Text
:
txt
})
}
}
return
result
return
result
...
@@ -247,12 +251,12 @@ func directoryListing(files []os.FileInfo, canGoUp bool, urlPath string, config
...
@@ -247,12 +251,12 @@ func directoryListing(files []os.FileInfo, canGoUp bool, urlPath string, config
fileCount
++
fileCount
++
}
}
url
:=
url
.
URL
{
Path
:
"./"
+
name
}
// prepend with "./" to fix paths with ':' in the name
if
config
.
Fs
.
IsHidden
(
f
)
{
if
config
.
Fs
.
IsHidden
(
f
)
{
continue
continue
}
}
url
:=
url
.
URL
{
Path
:
"./"
+
name
}
// prepend with "./" to fix paths with ':' in the name
fileinfos
=
append
(
fileinfos
,
FileInfo
{
fileinfos
=
append
(
fileinfos
,
FileInfo
{
IsDir
:
f
.
IsDir
(),
IsDir
:
f
.
IsDir
(),
Name
:
f
.
Name
(),
Name
:
f
.
Name
(),
...
...
caddyhttp/browse/setup.go
View file @
3ca419e2
...
@@ -323,7 +323,7 @@ footer {
...
@@ -323,7 +323,7 @@ footer {
<header>
<header>
<h1>
<h1>
{{range $
url, $name := .BreadcrumbMap}}<a href="{{html $url}}">{{html $name}}</a>{{if ne $url "/"
}}/{{end}}{{end}}
{{range $
i, $crumb := .Breadcrumbs}}<a href="{{html $crumb.Link}}">{{html $crumb.Text}}</a>{{if ne $i 0
}}/{{end}}{{end}}
</h1>
</h1>
</header>
</header>
<main>
<main>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment