@@ -13,6 +13,7 @@ import (
13
13
// structs for directory listing
14
14
type listingTemplateData struct {
15
15
GatewayURL string
16
+ DNSLink bool
16
17
Listing []directoryItem
17
18
Size string
18
19
Path string
@@ -34,7 +35,7 @@ type breadcrumb struct {
34
35
Path string
35
36
}
36
37
37
- func breadcrumbs (urlPath string , gwRootURL string ) []breadcrumb {
38
+ func breadcrumbs (urlPath string , dnslinkOrigin bool ) []breadcrumb {
38
39
var ret []breadcrumb
39
40
40
41
p , err := ipfspath .ParsePath (urlPath )
@@ -43,7 +44,6 @@ func breadcrumbs(urlPath string, gwRootURL string) []breadcrumb {
43
44
return ret
44
45
}
45
46
segs := p .Segments ()
46
- ns := segs [0 ]
47
47
contentRoot := segs [1 ]
48
48
for i , seg := range segs {
49
49
if i == 0 {
@@ -56,10 +56,11 @@ func breadcrumbs(urlPath string, gwRootURL string) []breadcrumb {
56
56
}
57
57
}
58
58
59
- // Drop the /ipns/<fqdn> prefix from breadcrumb Paths when directory listing
60
- // on a DNSLink website (loaded due to Host header in HTTP request).
61
- // Necessary because gwRootURL won't have a public gateway mounted.
62
- if ns == "ipns" && (("//" + contentRoot ) == gwRootURL ) {
59
+ // Drop the /ipns/<fqdn> prefix from breadcrumb Paths when directory
60
+ // listing on a DNSLink website (loaded due to Host header in HTTP
61
+ // request). Necessary because the hostname most likely won't have a
62
+ // public gateway mounted.
63
+ if dnslinkOrigin {
63
64
prefix := "/ipns/" + contentRoot
64
65
for i , crumb := range ret {
65
66
if strings .HasPrefix (crumb .Path , prefix ) {
@@ -77,6 +78,16 @@ func shortHash(hash string) string {
77
78
return (hash [0 :4 ] + "\u2026 " + hash [len (hash )- 4 :])
78
79
}
79
80
81
+ // helper to detect DNSLink website context
82
+ // (when hostname from gwURL is matching /ipns/<fqdn> in path)
83
+ func hasDNSLinkOrigin (gwURL string , path string ) bool {
84
+ if gwURL != "" {
85
+ dnslinkRoot := strings .Replace (gwURL , "//" , "/ipns/" , 1 )
86
+ return strings .HasPrefix (path , dnslinkRoot )
87
+ }
88
+ return false
89
+ }
90
+
80
91
var listingTemplate * template.Template
81
92
82
93
func init () {
0 commit comments