From 8c03fc4579b8a65b019629eab08573c10b299285 Mon Sep 17 00:00:00 2001 From: Kevin Neaton Date: Thu, 2 Jul 2020 20:44:26 -0400 Subject: [PATCH] Make path components into links --- dir-index.html | 9 ++++++++- test/main.go | 32 +++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/dir-index.html b/dir-index.html index 2e5d507..7f2ce11 100644 --- a/dir-index.html +++ b/dir-index.html @@ -55,7 +55,14 @@
- Index of {{ .Path }} + + Index of + {{ range .Breadcrumbs -}} + /{{ if .Path }}{{ .Name }}{{ else }}{{ .Name }}{{ end }} + {{- else }} + {{ .Path }} + {{ end }} + {{ if .Hash }}
{{ .Hash }} diff --git a/test/main.go b/test/main.go index e4a4153..6c851ae 100644 --- a/test/main.go +++ b/test/main.go @@ -15,6 +15,7 @@ type listingTemplateData struct { Listing []directoryItem Size string Path string + Breadcrumbs []breadcrumb BackLink string Hash string } @@ -25,20 +26,41 @@ type directoryItem struct { Path string } +type breadcrumb struct { + Name string + Path string +} + +var testPath = "/ipfs/QmFooBarQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7/a/b/c" var testData = listingTemplateData{ Listing: []directoryItem{{ Size: "25 MiB", Name: "short-film.mov", - Path: "short-film.mov", + Path: testPath + "/short-film.mov", }, { Size: "1 KiB", Name: "this-piece-of-papers-got-47-words-37-sentences-58-words-we-wanna-know.txt", - Path: "this-piece-of-papers-got-47-words-37-sentences-58-words-we-wanna-know.txt", + Path: testPath + "/this-piece-of-papers-got-47-words-37-sentences-58-words-we-wanna-know.txt", }}, Size: "25 MiB", - Path: "/ipfs/QmFooBarQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7RgQm", - BackLink: "/..", - Hash: "QmFooBarQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7RgQm", + Path: testPath, + Breadcrumbs: []breadcrumb{{ + Name: "ipfs", + }, { + Name: "QmFooBarQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7", + Path: testPath + "/../../..", + }, { + Name: "a", + Path: testPath + "/../..", + }, { + Name: "b", + Path: testPath + "/..", + }, { + Name: "c", + Path: testPath, + }}, + BackLink: testPath + "/..", + Hash: "QmFooBazBar2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7", } func main() { -- GitLab