From 0531e93b64ba92f732b35a386654d4d5f4d133ee Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 24 Nov 2022 17:39:52 +0100 Subject: [PATCH] refactor: create template at assets/dag-index-html This is a quick, static placeholder that follows the style of dir-index-html. Future work will refine this, perhaps by reusing parts of https://explore.ipld.io/ --- assets/dag-index-html/README.md | 3 + assets/dag-index-html/index.go | 81 ++++++++++++++++++++++++ assets/dir-index-html/README.md | 2 +- assets/dir-index-html/dir-index.html | 12 ++-- assets/dir-index-html/src/dir-index.html | 12 ++-- core/corehttp/gateway_handler_codec.go | 34 ++++------ 6 files changed, 108 insertions(+), 36 deletions(-) create mode 100644 assets/dag-index-html/README.md create mode 100644 assets/dag-index-html/index.go diff --git a/assets/dag-index-html/README.md b/assets/dag-index-html/README.md new file mode 100644 index 000000000000..de38a9504a1e --- /dev/null +++ b/assets/dag-index-html/README.md @@ -0,0 +1,3 @@ +# dag-index-html + +> HTML representation for non-UnixFS DAGs such as DAG-CBOR. diff --git a/assets/dag-index-html/index.go b/assets/dag-index-html/index.go new file mode 100644 index 000000000000..a3782f19cee5 --- /dev/null +++ b/assets/dag-index-html/index.go @@ -0,0 +1,81 @@ +package dagindexhtml + +import "html/template" + +// HTML-based template for non-UnixFS DAGs when request was made with +// Accept: text/html. +// TODO: replace static CSS with shared one with ../dir-index-html +var DagIndexTemplate = template.Must(template.New("redirect").Parse(` + + + + + + + + + + + + + + + + + + {{ .Path }} + + + + +
+
+

CID: {{.CID}}
+ Codec: {{.CodecName}} ({{.CodecHex}})

+

This CID is not UnixFS (not a file, nor a directory)

+
+
+ + + + + + + +
+

Preview as JSON
(application/json)

+
+

Or download as: +

+

+
+
+
+ +`)) + +type DagIndexTemplateData struct { + Path string + CID string + CodecName string + CodecHex string +} diff --git a/assets/dir-index-html/README.md b/assets/dir-index-html/README.md index ad5fa68b2db5..3dd45eb59056 100644 --- a/assets/dir-index-html/README.md +++ b/assets/dir-index-html/README.md @@ -1,6 +1,6 @@ # dir-index-html -> Directory listing HTML for `go-ipfs` gateways +> Directory listing HTML for HTTP gateway ![](https://user-images.githubusercontent.com/157609/88379209-ce6f0600-cda2-11ea-9620-20b9237bb441.png) diff --git a/assets/dir-index-html/dir-index.html b/assets/dir-index-html/dir-index.html index a2d662d19c7b..1d00e5fe73f6 100644 --- a/assets/dir-index-html/dir-index.html +++ b/assets/dir-index-html/dir-index.html @@ -26,12 +26,12 @@