Skip to content
This repository was archived by the owner on Mar 22, 2022. It is now read-only.

Commit 3f67a81

Browse files
committed
feat: improved CID column
- Links to direct CIDs now have ?filename= param to preserve name and content type - When page is loaded on DNSLink website (based on Host header) then there is no public gateway endpoint. As a replacement, clicking on a CID opens it at cid.ipfs.io Context: #42 Closes #42
1 parent dc0400b commit 3f67a81

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

dir-index.html

+2-2
Large diffs are not rendered by default.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"license": "MIT",
1818
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
1919
"scripts": {
20+
"start": "cd test && go run .",
2021
"build": "npm run build:clean && npm run build:remove-style-links && npm run build:minify-wrap-css && npm run build:combine-html-css && npm run build:remove-unused",
2122
"build:clean": "rm dir-index.html",
2223
"build:remove-style-links": "sed '/<link rel=\"stylesheet\"/d' ./src/dir-index.html > ./base-html.html",

src/dir-index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
</td>
8282
<td class="no-linebreak">
8383
{{ if .Hash }}
84-
<a class="ipfs-hash" href="{{ $root.GatewayURL }}/ipfs/{{ .Hash | urlEscape }}">
84+
<a class="ipfs-hash" 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 }}>
8585
{{ .ShortHash }}
8686
</a>
8787
{{ end }}

test/main.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const templateFile = "../dir-index.html"
1313
// Copied from go-ipfs/core/corehttp/gateway_indexPage.go
1414
type listingTemplateData struct {
1515
GatewayURL string
16+
DNSLink bool
1617
Listing []directoryItem
1718
Size string
1819
Path string
@@ -37,18 +38,25 @@ type breadcrumb struct {
3738
var testPath = "/ipfs/QmFooBarQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7/a/b/c"
3839
var testData = listingTemplateData{
3940
GatewayURL: "//localhost:3000",
41+
DNSLink: true,
4042
Listing: []directoryItem{{
4143
Size: "25 MiB",
4244
Name: "short-film.mov",
4345
Path: testPath + "/short-film.mov",
44-
Hash: "QmQuxBarQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7",
45-
ShortHash: "QmQu\u2026xDu7",
46+
Hash: "QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR",
47+
ShortHash: "QmbW\u2026sMnR",
48+
}, {
49+
Size: "23 KiB",
50+
Name: "250pxيوسف_الوزاني_صورة_ملتقطة_بواسطة_مرصد_هابل_الفضائي_توضح_سديم_السرطان،_وهو_بقايا_مستعر_أعظم._.jpg",
51+
Path: testPath + "/250pxيوسف_الوزاني_صورة_ملتقطة_بواسطة_مرصد_هابل_الفضائي_توضح_سديم_السرطان،_وهو_بقايا_مستعر_أعظم._.jpg",
52+
Hash: "QmUwrKrMTrNv8QjWGKMMH5QV9FMPUtRCoQ6zxTdgxATQW6",
53+
ShortHash: "QmUw\u2026TQW6",
4654
}, {
4755
Size: "1 KiB",
4856
Name: "this-piece-of-papers-got-47-words-37-sentences-58-words-we-wanna-know.txt",
4957
Path: testPath + "/this-piece-of-papers-got-47-words-37-sentences-58-words-we-wanna-know.txt",
50-
Hash: "QmquXbaRQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7",
51-
ShortHash: "Qmqu\u2026xDu7",
58+
Hash: "bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi",
59+
ShortHash: "bafy\u2026bzdi",
5260
}},
5361
Size: "25 MiB",
5462
Path: testPath,

0 commit comments

Comments
 (0)