@cryptotaxi247 / kubo / commits / 8c03fc457

Make path components into links

Kevin Neaton committed Jul 2, 2020 at 20:44 UTC 8c03fc4579b8a65b019629eab08573c10b299285
2 files changed +35 -6
dir-index.html
+8 -1
@@ -55,7 +55,14 @@
55 <div id="content">
56 <div id="content-header" class="d-flex flex-wrap">
57 <div>
58 - <strong>Index of {{ .Path }}</strong>
58 + <strong>
59 + Index of
60 + {{ range .Breadcrumbs -}}
61 + /{{ if .Path }}<a href="{{ .Path | urlEscape }}">{{ .Name }}</a>{{ else }}{{ .Name }}{{ end }}
62 + {{- else }}
63 + {{ .Path }}
64 + {{ end }}
65 + </strong>
66 {{ if .Hash }}
67 <div class="ipfs-hash">
68 {{ .Hash }}
test/main.go
+27 -5
@@ -15,6 +15,7 @@ type listingTemplateData struct {
15 Listing []directoryItem
16 Size string
17 Path string
18 + Breadcrumbs []breadcrumb
19 BackLink string
20 Hash string
21 }
@@ -25,20 +26,41 @@ type directoryItem struct {
26 Path string
27 }
28
29 +type breadcrumb struct {
30 + Name string
31 + Path string
32 +}
33 +
34 +var testPath = "/ipfs/QmFooBarQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7/a/b/c"
35 var testData = listingTemplateData{
36 Listing: []directoryItem{{
37 Size: "25 MiB",
38 Name: "short-film.mov",
32 - Path: "short-film.mov",
39 + Path: testPath + "/short-film.mov",
40 }, {
41 Size: "1 KiB",
42 Name: "this-piece-of-papers-got-47-words-37-sentences-58-words-we-wanna-know.txt",
36 - Path: "this-piece-of-papers-got-47-words-37-sentences-58-words-we-wanna-know.txt",
43 + Path: testPath + "/this-piece-of-papers-got-47-words-37-sentences-58-words-we-wanna-know.txt",
44 }},
45 Size: "25 MiB",
39 - Path: "/ipfs/QmFooBarQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7RgQm",
40 - BackLink: "/..",
41 - Hash: "QmFooBarQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7RgQm",
46 + Path: testPath,
47 + Breadcrumbs: []breadcrumb{{
48 + Name: "ipfs",
49 + }, {
50 + Name: "QmFooBarQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7",
51 + Path: testPath + "/../../..",
52 + }, {
53 + Name: "a",
54 + Path: testPath + "/../..",
55 + }, {
56 + Name: "b",
57 + Path: testPath + "/..",
58 + }, {
59 + Name: "c",
60 + Path: testPath,
61 + }},
62 + BackLink: testPath + "/..",
63 + Hash: "QmFooBazBar2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7",
64 }
65
66 func main() {