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

feat: improved CID column (filename and dnslink support) #43

Merged
merged 2 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: '12.x'
- run: npm run build
- run: npm run build
- name: Check working tree
id: changes
uses: UnicornGlobal/has-changes-action@v1.0.11
- name: Check for uncommited changes
if: steps.changes.outputs.changed == 1
run: git status && echo "Output does not match src/, uncommitted changes exist, follow build instructions from README" && exit 1
run: git status && git --no-pager diff --patch-with-raw && echo "Output does not match src/, uncommitted changes exist, follow build instructions from README" && exit 1
4 changes: 2 additions & 2 deletions dir-index.html

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
"license": "MIT",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"scripts": {
"start": "cd test && go run .",
"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",
"build:clean": "rm dir-index.html",
"build:remove-style-links": "sed '/<link rel=\"stylesheet\"/d' ./src/dir-index.html > ./base-html.html",
"build:minify-wrap-css": "(echo \"<style>\" && cat ./src/icons.css ./src/style.css | tr -d \"\t\n\r\" && echo -e \"\\n</style>\") > ./minified-wrapped-style.html",
"build:minify-wrap-css": "(echo \"<style>\" && cat ./src/icons.css ./src/style.css | tr -d \"\t\n\r\" && echo && echo \"</style>\") > ./minified-wrapped-style.html",
"build:combine-html-css": "sed '/<head>/ r ./minified-wrapped-style.html' ./base-html.html > ./dir-index.html",
"build:remove-unused": "rm ./base-html.html && rm ./minified-wrapped-style.html"
}
Expand Down
2 changes: 1 addition & 1 deletion src/dir-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
</td>
<td class="no-linebreak">
{{ if .Hash }}
<a class="ipfs-hash" href="{{ $root.GatewayURL }}/ipfs/{{ .Hash | urlEscape }}">
<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 }}>
{{ .ShortHash }}
</a>
{{ end }}
Expand Down
16 changes: 12 additions & 4 deletions test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const templateFile = "../dir-index.html"
// Copied from go-ipfs/core/corehttp/gateway_indexPage.go
type listingTemplateData struct {
GatewayURL string
DNSLink bool
Listing []directoryItem
Size string
Path string
Expand All @@ -37,18 +38,25 @@ type breadcrumb struct {
var testPath = "/ipfs/QmFooBarQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7/a/b/c"
var testData = listingTemplateData{
GatewayURL: "//localhost:3000",
DNSLink: true,
Listing: []directoryItem{{
Size: "25 MiB",
Name: "short-film.mov",
Path: testPath + "/short-film.mov",
Hash: "QmQuxBarQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7",
ShortHash: "QmQu\u2026xDu7",
Hash: "QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR",
ShortHash: "QmbW\u2026sMnR",
}, {
Size: "23 KiB",
Name: "250pxيوسف_الوزاني_صورة_ملتقطة_بواسطة_مرصد_هابل_الفضائي_توضح_سديم_السرطان،_وهو_بقايا_مستعر_أعظم._.jpg",
Path: testPath + "/250pxيوسف_الوزاني_صورة_ملتقطة_بواسطة_مرصد_هابل_الفضائي_توضح_سديم_السرطان،_وهو_بقايا_مستعر_أعظم._.jpg",
Hash: "QmUwrKrMTrNv8QjWGKMMH5QV9FMPUtRCoQ6zxTdgxATQW6",
ShortHash: "QmUw\u2026TQW6",
}, {
Size: "1 KiB",
Name: "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",
Hash: "QmquXbaRQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7",
ShortHash: "Qmqu\u2026xDu7",
Hash: "bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi",
ShortHash: "bafy\u2026bzdi",
}},
Size: "25 MiB",
Path: testPath,
Expand Down