|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <title>Artifact Explorer</title> |
| 6 | + <!-- PicoCSS via CDN --> |
| 7 | + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@latest/css/pico.min.css"> |
| 8 | + <style> |
| 9 | + .file-list { |
| 10 | + list-style: none; |
| 11 | + padding-left: 1rem; |
| 12 | + } |
| 13 | + .file-list li { |
| 14 | + margin: 0.5rem 0; |
| 15 | + } |
| 16 | + .breadcrumb { |
| 17 | + margin-bottom: 1rem; |
| 18 | + } |
| 19 | + .breadcrumb a { |
| 20 | + text-decoration: none; |
| 21 | + } |
| 22 | + </style> |
| 23 | +</head> |
| 24 | +<body> |
| 25 | + <header> |
| 26 | + <h1>Artifact Explorer</h1> |
| 27 | + </header> |
| 28 | + <main> |
| 29 | + <!-- Breadcrumb navigation --> |
| 30 | + <nav id="breadcrumb" class="breadcrumb"></nav> |
| 31 | + <!-- File and folder list --> |
| 32 | + <ul id="fileList" class="file-list"></ul> |
| 33 | + </main> |
| 34 | + |
| 35 | + <script> |
| 36 | + let fileTree = null; |
| 37 | + // breadcrumb holds the nodes from the root (index 0) to the current directory. |
| 38 | + let breadcrumb = []; |
| 39 | + |
| 40 | + // Compute the relative URL for a child node. |
| 41 | + // If the root is "public" and you want to hide it, skip it in the URL. |
| 42 | + function computePath(child) { |
| 43 | + // Build parts from breadcrumb (skipping the root if its name is "public") |
| 44 | + let parts = []; |
| 45 | + for (let i = 0; i < breadcrumb.length; i++) { |
| 46 | + if (i === 0 && breadcrumb[i].name === "public") continue; |
| 47 | + parts.push(breadcrumb[i].name); |
| 48 | + } |
| 49 | + parts.push(child.name); |
| 50 | + return parts.join('/'); |
| 51 | + } |
| 52 | + |
| 53 | + // Render breadcrumb navigation. |
| 54 | + function renderBreadcrumb() { |
| 55 | + const nav = document.getElementById('breadcrumb'); |
| 56 | + nav.innerHTML = ''; |
| 57 | + |
| 58 | + // Always add a link to the root. |
| 59 | + const rootLink = document.createElement('a'); |
| 60 | + rootLink.href = '#'; |
| 61 | + rootLink.textContent = breadcrumb[0].name; |
| 62 | + rootLink.addEventListener('click', (e) => { |
| 63 | + e.preventDefault(); |
| 64 | + breadcrumb = [fileTree]; |
| 65 | + renderDirectory(fileTree); |
| 66 | + }); |
| 67 | + nav.appendChild(rootLink); |
| 68 | + |
| 69 | + // For subsequent levels, add links. |
| 70 | + for (let i = 1; i < breadcrumb.length; i++) { |
| 71 | + const separator = document.createTextNode(' / '); |
| 72 | + nav.appendChild(separator); |
| 73 | + |
| 74 | + const link = document.createElement('a'); |
| 75 | + link.href = '#'; |
| 76 | + link.textContent = breadcrumb[i].name; |
| 77 | + // Clicking a breadcrumb link goes back to that level. |
| 78 | + link.addEventListener('click', (e) => { |
| 79 | + e.preventDefault(); |
| 80 | + breadcrumb = breadcrumb.slice(0, i + 1); |
| 81 | + renderDirectory(breadcrumb[breadcrumb.length - 1]); |
| 82 | + }); |
| 83 | + nav.appendChild(link); |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + // Render the list of files and directories for a given node. |
| 88 | + function renderDirectory(node) { |
| 89 | + renderBreadcrumb(); |
| 90 | + const list = document.getElementById('fileList'); |
| 91 | + list.innerHTML = ''; |
| 92 | + |
| 93 | + // Ensure we have a "contents" array. |
| 94 | + if (!node.contents || node.contents.length === 0) { |
| 95 | + const li = document.createElement('li'); |
| 96 | + li.textContent = 'No files or folders here.'; |
| 97 | + list.appendChild(li); |
| 98 | + return; |
| 99 | + } |
| 100 | + |
| 101 | + // Sort directories first. |
| 102 | + const sortedItems = node.contents.slice().sort((a, b) => { |
| 103 | + if (a.type === b.type) return a.name.localeCompare(b.name); |
| 104 | + return a.type === 'directory' ? -1 : 1; |
| 105 | + }); |
| 106 | + |
| 107 | + sortedItems.forEach(item => { |
| 108 | + const li = document.createElement('li'); |
| 109 | + const link = document.createElement('a'); |
| 110 | + link.href = '#'; |
| 111 | + |
| 112 | + if (item.type === 'directory') { |
| 113 | + link.textContent = item.name + '/'; |
| 114 | + link.addEventListener('click', (e) => { |
| 115 | + e.preventDefault(); |
| 116 | + breadcrumb.push(item); |
| 117 | + renderDirectory(item); |
| 118 | + }); |
| 119 | + } else if (item.type === 'file') { |
| 120 | + // For files, compute the URL for download. |
| 121 | + const filePath = computePath(item); |
| 122 | + link.href = filePath; |
| 123 | + link.textContent = item.name; |
| 124 | + // Optionally, you can add link.download = item.name; if you want to force download. |
| 125 | + } |
| 126 | + li.appendChild(link); |
| 127 | + list.appendChild(li); |
| 128 | + }); |
| 129 | + } |
| 130 | + |
| 131 | + // Fetch the JSON manifest (output of tree -J) |
| 132 | + fetch('files.json') |
| 133 | + .then(response => response.json()) |
| 134 | + .then(data => { |
| 135 | + // data is an array with a single element. |
| 136 | + fileTree = data[0]; |
| 137 | + // Initialize breadcrumb with the root. |
| 138 | + breadcrumb = [fileTree]; |
| 139 | + renderDirectory(fileTree); |
| 140 | + }) |
| 141 | + .catch(error => console.error('Error loading file manifest:', error)); |
| 142 | + </script> |
| 143 | +</body> |
| 144 | +</html> |
0 commit comments