-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex-all.html
More file actions
344 lines (315 loc) · 11.5 KB
/
index-all.html
File metadata and controls
344 lines (315 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<!DOCTYPE html>
<html>
<head>
<title>File Explorer</title>
<!-- Highlight.js CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/github.min.css">
<!-- Load highlight.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
<!-- Load language support -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/languages/yaml.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/languages/json.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/languages/dockerfile.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/languages/bash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/languages/python.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/languages/javascript.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
height: 100vh;
box-sizing: border-box;
display: flex;
flex-direction: column;
}
.container {
display: flex;
flex: 1;
gap: 20px;
height: calc(100% - 80px);
overflow: hidden;
}
.file-list-container {
flex: 1;
border: 1px solid #ddd;
border-radius: 4px;
overflow: hidden;
display: flex;
flex-direction: column;
}
.file-list-header {
padding: 10px;
background: #f8f9fa;
border-bottom: 1px solid #ddd;
font-weight: bold;
}
#file-list {
flex: 1;
overflow-y: auto;
padding: 10px 0;
}
.file {
padding: 8px 15px;
cursor: pointer;
display: flex;
align-items: center;
gap: 8px;
}
.file:hover {
background: #f0f0f0;
}
.dir {
font-weight: bold;
}
.file-content-container {
flex: 2;
border: 1px solid #ddd;
border-radius: 4px;
overflow: hidden;
display: flex;
flex-direction: column;
}
.file-content-header {
padding: 10px;
background: #f8f9fa;
border-bottom: 1px solid #ddd;
font-weight: bold;
}
#file-content {
flex: 1;
padding: 15px;
background: white;
overflow-y: auto;
margin: 0;
}
pre {
margin: 0;
padding: 1em;
white-space: pre-wrap;
font-family: 'Fira Code', 'Consolas', 'Monaco', 'Andale Mono', monospace;
font-size: 14px;
line-height: 1.5;
border-radius: 4px;
background: #f6f8fa !important;
overflow-x: auto;
}
/* Add some spacing for code blocks */
code {
font-family: 'Fira Code', 'Consolas', 'Monaco', 'Andale Mono', monospace;
}
/* Fix for JSON syntax highlighting */
.hljs-attr {
color: #d946ef;
}
/* Make line numbers visible */
.hljs-ln {
padding: 0;
}
.hljs-ln-n {
padding-right: 1em;
color: #6e7781;
user-select: none;
}
.breadcrumb {
margin-bottom: 15px;
padding: 10px 15px;
background: #f8f9fa;
border-radius: 4px;
}
.breadcrumb a {
color: #007bff;
text-decoration: none;
}
.breadcrumb a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>File Explorer</h1>
<div class="breadcrumb" id="breadcrumb">
<a href="#" data-path="">Root</a>
</div>
<div class="container">
<div class="file-list-container">
<div class="file-list-header">Files</div>
<div id="file-list">Loading...</div>
</div>
<div class="file-content-container">
<div class="file-content-header">File Content</div>
<div id="file-content">Select a file to view its contents</div>
</div>
</div>
<script>
let fileSystem = null;
let currentPath = [];
// Load file system data
async function loadFileSystem() {
try {
const response = await fetch('data/file-system.json');
fileSystem = await response.json();
renderFileList();
} catch (error) {
document.getElementById('file-list').innerHTML = 'Error loading file system: ' + error.message;
}
}
// Render file list for current path
function renderFileList() {
const fileList = document.getElementById('file-list');
const currentDir = getCurrentDir();
if (!currentDir || !currentDir.children) {
fileList.innerHTML = 'No files found';
return;
}
let html = '';
currentDir.children.forEach(item => {
const isDir = item.type === 'directory';
html += `
<div class="file ${isDir ? 'dir' : ''}"
data-type="${item.type}"
data-path="${item.path}">
<span>${isDir ? '[DIR]' : '[FILE]'}</span>
<span>${item.name}</span>
${!isDir ? `<span>${formatFileSize(item.size)}</span>` : ''}
</div>`;
});
fileList.innerHTML = html || 'Empty directory';
// Add click handlers
document.querySelectorAll('.file').forEach(el => {
el.addEventListener('click', handleFileClick);
});
}
// Handle file/directory click
function handleFileClick(e) {
const type = this.getAttribute('data-type');
const path = this.getAttribute('data-path').split('/').filter(Boolean);
if (type === 'directory') {
currentPath = path;
renderBreadcrumb();
renderFileList();
document.getElementById('file-content').innerHTML = '';
} else {
showFileContent(path[path.length - 1]);
}
}
// Show file content
function getLanguageFromFilename(filename) {
const ext = filename.split('.').pop().toLowerCase();
const languageMap = {
'js': 'javascript',
'jsx': 'javascript',
'ts': 'typescript',
'tsx': 'typescript',
'py': 'python',
'rb': 'ruby',
'java': 'java',
'c': 'c',
'cpp': 'cpp',
'cs': 'csharp',
'php': 'php',
'sh': 'bash',
'json': 'json',
'yaml': 'yaml',
'yml': 'yaml',
'xml': 'xml',
'html': 'html',
'css': 'css',
'scss': 'scss',
'sql': 'sql',
'md': 'markdown',
'dockerfile': 'dockerfile',
'go': 'go',
'rs': 'rust',
'swift': 'swift',
'kt': 'kotlin',
'dart': 'dart'
};
return languageMap[ext] || 'plaintext';
}
function showFileContent(filename) {
const currentDir = getCurrentDir();
const file = currentDir.children.find(f => f.name === filename);
const contentDiv = document.getElementById('file-content');
if (!file || !file.content) {
contentDiv.innerHTML = 'No content to display';
return;
}
try {
const language = getLanguageFromFilename(filename);
let content = file.content;
// Format JSON if needed
if (language === 'json') {
try {
content = JSON.stringify(JSON.parse(content), null, 2);
} catch (e) {
console.warn('Error parsing JSON:', e);
}
}
// Escape HTML and add syntax highlighting
const escaped = escapeHtml(content);
contentDiv.innerHTML = `<pre><code class="language-${language}">${escaped}</code></pre>`;
// Apply syntax highlighting
document.querySelectorAll('pre code').forEach((block) => {
hljs.highlightElement(block);
});
} catch (error) {
console.error('Error displaying file content:', error);
contentDiv.innerHTML = `<pre>${escapeHtml(file.content)}</pre>`;
}
}
// Render breadcrumb navigation
function renderBreadcrumb() {
const breadcrumb = document.getElementById('breadcrumb');
let html = '<a href="#" data-path="">Root</a>';
currentPath.forEach((segment, index) => {
const path = currentPath.slice(0, index + 1).join('/');
html += ` / <a href="#" data-path="${path}">${segment}</a>`;
});
breadcrumb.innerHTML = html;
// Add click handlers to breadcrumb links
breadcrumb.querySelectorAll('a').forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const path = link.getAttribute('data-path');
currentPath = path ? path.split('/') : [];
renderBreadcrumb();
renderFileList();
document.getElementById('file-content').innerHTML = '';
});
});
}
// Get current directory based on path
function getCurrentDir() {
let current = fileSystem;
for (const segment of currentPath) {
if (!current.children) return null;
const found = current.children.find(item => item.name === segment);
if (!found) return null;
current = found;
}
return current;
}
// Helper functions
function formatFileSize(bytes) {
if (!bytes) return '0 B';
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
// Initialize
document.addEventListener('DOMContentLoaded', () => {
loadFileSystem();
});
</script>
</body>
</html>