-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsitemap_js.html
More file actions
116 lines (99 loc) · 3.59 KB
/
Copy pathsitemap_js.html
File metadata and controls
116 lines (99 loc) · 3.59 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
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<style>
a {
color: inherit;
text-decoration: none;
}
#main, .main {
display: flex;
gap: 1vh 1vw;
}
#folders {
display: grid;
grid-template-columns: 10vw auto;
grid-row-gap: 2px;
padding: 10px;
}
#folders > label, #folders > .main {
border: 2px solid black;
padding: 10px;
}
#folders > .main {
border-left: none;
}
#folders > label {
font-size: min(2vw, 2vh);
border-right: none;
align-content: center;
}
.item {
place-items: center;
display: grid;
border: gray solid 2px;
padding: 1vh 1vw;
}
.icon {
font-size: 5vw;
}
</style>
</head>
<body>
<div id="folders"></div>
<script>
create_icon = (name, icon)=>{
let div = document.createElement('div');
div.classList.add('item');
let idiv = document.createElement('div');
idiv.classList.add('icon');
idiv.textContent = icon;
div.appendChild(idiv);
let text = document.createElement('span');
text.textContent = name;
div.appendChild(text);
return div
}
create_folder = (folder_name, folder_path)=>{
let div = create_icon(folder_name, '📁');
let hash = new URL(`${folder_path}${folder_name}/`, window.location.origin).pathname.slice(1);
let url = new URL('/index.html', window.location.origin);
url.hash = hash;
div.onclick = ()=>{window.location.href = url.href}
return div
}
create_file = (file_name, folder_path)=>{
let div = create_icon(file_name, '📄');
// TODO: implement support for navigation with folder
let a = document.createElement('a');
a.href = folder_path + file_name;
a.appendChild(div);
return a
}
async function render_folder(div, dirs, file, folder_path){
for (let folder of dirs){
div.appendChild(create_folder(folder, folder_path));
}
for (let file of files){
div.appendChild(create_file(file, folder_path));
}
}
async function main(){
r = await fetch('json_index.json');
j = await r.json();
for ([folder_path, [dirs, files]] of Object.entries(j)){
let div = document.createElement('div');
div.classList.add('main');
render_folder(div, dirs, files, folder_path+'\\');
let label = document.createElement('label');
label.textContent = folder_path;
folders = document.getElementById('folders');
folders.appendChild(label);
folders.appendChild(div);
}
}
main()
</script>
</body>
</html>