Skip to content

Commit 0531e93

Browse files
committed
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/
1 parent ff55745 commit 0531e93

File tree

6 files changed

+108
-36
lines changed

6 files changed

+108
-36
lines changed

assets/dag-index-html/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# dag-index-html
2+
3+
> HTML representation for non-UnixFS DAGs such as DAG-CBOR.

assets/dag-index-html/index.go

+81
Large diffs are not rendered by default.

assets/dir-index-html/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# dir-index-html
22

3-
> Directory listing HTML for `go-ipfs` gateways
3+
> Directory listing HTML for HTTP gateway
44
55
![](https://user-images.githubusercontent.com/157609/88379209-ce6f0600-cda2-11ea-9620-20b9237bb441.png)
66

assets/dir-index-html/dir-index.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
<div id="page-header">
2727
<div id="page-header-logo" class="ipfs-logo">&nbsp;</div>
2828
<div id="page-header-menu">
29-
<div class="menu-item-wide"><a href="https://ipfs.io" target="_blank" rel="noopener noreferrer">About IPFS</a></div>
30-
<div class="menu-item-wide"><a href="https://ipfs.io#install" target="_blank" rel="noopener noreferrer">Install IPFS</a></div>
31-
<div class="menu-item-narrow"><a href="https://ipfs.io" target="_blank" rel="noopener noreferrer">About</a></div>
32-
<div class="menu-item-narrow"><a href="https://ipfs.io#install" target="_blank" rel="noopener noreferrer">Install</a></div>
29+
<div class="menu-item-wide"><a href="https://ipfs.tech" target="_blank" rel="noopener noreferrer">About IPFS</a></div>
30+
<div class="menu-item-wide"><a href="https://ipfs.tech#install" target="_blank" rel="noopener noreferrer">Install IPFS</a></div>
31+
<div class="menu-item-narrow"><a href="https://ipfs.tech" target="_blank" rel="noopener noreferrer">About</a></div>
32+
<div class="menu-item-narrow"><a href="https://ipfs.tech#install" target="_blank" rel="noopener noreferrer">Install</a></div>
3333
<div>
34-
<a href="https://github.com/ipfs/go-ipfs/issues/new/choose" target="_blank" rel="noopener noreferrer" title="Report a bug">
34+
<a href="https://github.com/ipfs/kubo/issues/new/choose" target="_blank" rel="noopener noreferrer" title="Report a bug">
3535
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18.4 21"><circle cx="7.5" cy="4.8" r="1"/><circle cx="11.1" cy="4.8" r="1"/><path d="M12.7 8.4c-0.5-1.5-1.9-2.5-3.5-2.5 -1.6 0-3 1-3.5 2.5H12.7z"/><path d="M8.5 9.7H5c-0.5 0.8-0.7 1.7-0.7 2.7 0 2.6 1.8 4.8 4.2 5.2V9.7z"/><path d="M13.4 9.7H9.9v7.9c2.4-0.4 4.2-2.5 4.2-5.2C14.1 11.4 13.9 10.5 13.4 9.7z"/><circle cx="15.7" cy="12.9" r="1"/><circle cx="15.1" cy="15.4" r="1"/><circle cx="15.3" cy="10.4" r="1"/><circle cx="2.7" cy="12.9" r="1"/><circle cx="3.3" cy="15.4" r="1"/><circle cx="3.1" cy="10.4" r="1"/></svg>
3636
</a>
3737
</div>
@@ -84,7 +84,7 @@
8484
</td>
8585
<td class="no-linebreak">
8686
{{ if .Hash }}
87-
<a class="ipfs-hash" translate="no" href={{ if $root.DNSLink }}"https://cid.ipfs.io/#{{ .Hash | urlEscape}}" target="_blank" rel="noreferrer noopener"{{ else }}"{{ $root.GatewayURL }}/ipfs/{{ .Hash | urlEscape}}?filename={{ .Name | urlEscape }}"{{ end }}>
87+
<a class="ipfs-hash" translate="no" href={{ if $root.DNSLink }}"https://cid.ipfs.tech/#{{ .Hash | urlEscape}}" target="_blank" rel="noreferrer noopener"{{ else }}"{{ $root.GatewayURL }}/ipfs/{{ .Hash | urlEscape}}?filename={{ .Name | urlEscape }}"{{ end }}>
8888
{{ .ShortHash }}
8989
</a>
9090
{{ end }}

assets/dir-index-html/src/dir-index.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
<div id="page-header">
2626
<div id="page-header-logo" class="ipfs-logo">&nbsp;</div>
2727
<div id="page-header-menu">
28-
<div class="menu-item-wide"><a href="https://ipfs.io" target="_blank" rel="noopener noreferrer">About IPFS</a></div>
29-
<div class="menu-item-wide"><a href="https://ipfs.io#install" target="_blank" rel="noopener noreferrer">Install IPFS</a></div>
30-
<div class="menu-item-narrow"><a href="https://ipfs.io" target="_blank" rel="noopener noreferrer">About</a></div>
31-
<div class="menu-item-narrow"><a href="https://ipfs.io#install" target="_blank" rel="noopener noreferrer">Install</a></div>
28+
<div class="menu-item-wide"><a href="https://ipfs.tech" target="_blank" rel="noopener noreferrer">About IPFS</a></div>
29+
<div class="menu-item-wide"><a href="https://ipfs.tech#install" target="_blank" rel="noopener noreferrer">Install IPFS</a></div>
30+
<div class="menu-item-narrow"><a href="https://ipfs.tech" target="_blank" rel="noopener noreferrer">About</a></div>
31+
<div class="menu-item-narrow"><a href="https://ipfs.tech#install" target="_blank" rel="noopener noreferrer">Install</a></div>
3232
<div>
33-
<a href="https://github.com/ipfs/go-ipfs/issues/new/choose" target="_blank" rel="noopener noreferrer" title="Report a bug">
33+
<a href="https://github.com/ipfs/kubo/issues/new/choose" target="_blank" rel="noopener noreferrer" title="Report a bug">
3434
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18.4 21"><circle cx="7.5" cy="4.8" r="1"/><circle cx="11.1" cy="4.8" r="1"/><path d="M12.7 8.4c-0.5-1.5-1.9-2.5-3.5-2.5 -1.6 0-3 1-3.5 2.5H12.7z"/><path d="M8.5 9.7H5c-0.5 0.8-0.7 1.7-0.7 2.7 0 2.6 1.8 4.8 4.2 5.2V9.7z"/><path d="M13.4 9.7H9.9v7.9c2.4-0.4 4.2-2.5 4.2-5.2C14.1 11.4 13.9 10.5 13.4 9.7z"/><circle cx="15.7" cy="12.9" r="1"/><circle cx="15.1" cy="15.4" r="1"/><circle cx="15.3" cy="10.4" r="1"/><circle cx="2.7" cy="12.9" r="1"/><circle cx="3.3" cy="15.4" r="1"/><circle cx="3.1" cy="10.4" r="1"/></svg>
3535
</a>
3636
</div>
@@ -83,7 +83,7 @@
8383
</td>
8484
<td class="no-linebreak">
8585
{{ if .Hash }}
86-
<a class="ipfs-hash" translate="no" href={{ if $root.DNSLink }}"https://cid.ipfs.io/#{{ .Hash | urlEscape}}" target="_blank" rel="noreferrer noopener"{{ else }}"{{ $root.GatewayURL }}/ipfs/{{ .Hash | urlEscape}}?filename={{ .Name | urlEscape }}"{{ end }}>
86+
<a class="ipfs-hash" translate="no" href={{ if $root.DNSLink }}"https://cid.ipfs.tech/#{{ .Hash | urlEscape}}" target="_blank" rel="noreferrer noopener"{{ else }}"{{ $root.GatewayURL }}/ipfs/{{ .Hash | urlEscape}}?filename={{ .Name | urlEscape }}"{{ end }}>
8787
{{ .ShortHash }}
8888
</a>
8989
{{ end }}

core/corehttp/gateway_handler_codec.go

+11-23
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
ipldlegacy "github.com/ipfs/go-ipld-legacy"
1414
ipath "github.com/ipfs/interface-go-ipfs-core/path"
15+
dih "github.com/ipfs/kubo/assets/dag-index-html"
1516
"github.com/ipfs/kubo/tracing"
1617
"github.com/ipld/go-ipld-prime"
1718
"github.com/ipld/go-ipld-prime/multicodec"
@@ -117,29 +118,16 @@ func (i *gatewayHandler) serveCodec(ctx context.Context, w http.ResponseWriter,
117118
}
118119

119120
func (i *gatewayHandler) serveCodecHTML(ctx context.Context, w http.ResponseWriter, r *http.Request, resolvedPath ipath.Resolved, contentPath ipath.Path) {
120-
codecName := mc.Code(resolvedPath.Cid().Prefix().Codec).String()
121-
body := fmt.Sprintf(`<!DOCTYPE html>
122-
<html lang="en">
123-
<head>
124-
<meta charset="utf-8" />
125-
</head>
126-
<body>
127-
<p>Requested CID <code>%q</code> uses <code>%q</code> codec.</p>
128-
<ul>
129-
<li><a href="?format=json" rel="nofollow">Preview as JSON</a> (<code>application/json</code>)</li>
130-
<li>Download as
131-
<ul>
132-
<li><a href="?format=raw" rel="nofollow">Raw Block</a> (no conversion)</li>
133-
<li><a href="?format=dag-json" rel="nofollow">DAG-JSON</a> (specs at <a href="https://ipld.io/specs/codecs/dag-json/spec/" rel="noreferrer nofollow">IPLD</a> and <a href="https://www.iana.org/assignments/media-types/application/vnd.ipld.dag-json" rel="noreferrer nofollow">IANA</a>)</li>
134-
<li><a href="?format=dag-cbor" rel="nofollow">DAG-CBOR</a> (specs at <a href="https://ipld.io/specs/codecs/dag-cbor/spec/" rel="noreferrer nofollow">IPLD</a> and <a href="https://www.iana.org/assignments/media-types/application/vnd.ipld.dag-cbor" rel="noreferrer nofollow">IANA</a>)</li>
135-
</ul>
136-
</li>
137-
</ul>
138-
</body>
139-
</html>
140-
`, resolvedPath.Cid(), codecName)
141-
142-
_, _ = w.Write([]byte(body))
121+
// TODO: cache-control/etag like for DirIndex
122+
cidCodec := mc.Code(resolvedPath.Cid().Prefix().Codec)
123+
if err := dih.DagIndexTemplate.Execute(w, dih.DagIndexTemplateData{
124+
Path: contentPath.String(),
125+
CID: resolvedPath.Cid().String(),
126+
CodecName: cidCodec.String(),
127+
CodecHex: fmt.Sprintf("0x%x", uint64(cidCodec)),
128+
}); err != nil {
129+
webError(w, "failed to generate HTML listing for this DAG: retry without 'Accept: text/html'", err, http.StatusInternalServerError)
130+
}
143131
}
144132

145133
func (i *gatewayHandler) serveCodecRaw(ctx context.Context, w http.ResponseWriter, r *http.Request, resolvedPath ipath.Resolved, contentPath ipath.Path, contentType string) {

0 commit comments

Comments
 (0)