-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
134 lines (118 loc) · 4.41 KB
/
Copy pathscript.js
File metadata and controls
134 lines (118 loc) · 4.41 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
const container = document.getElementById("project-tree");
/*
static chosen to limit api calls.
seeing as i'm probably not going to be updating sites soon.
onto mobile apps!
Static site tree
Rules:
- folders = containers only
- sites = folders with index.html
- folders render first, then sites
*/
const TREE = {
folders: [
{
name: "hackathons",
folders: [],
sites: [
{ name: "backed", path: "hackathons/backed" }
]
},
{
name: "oldsites",
folders: [
{
name: "englishportfolio",
folders: [],
sites: [
{ name: "final", path: "oldsites/englishportfolio/final" },
{ name: "week1", path: "oldsites/englishportfolio/week1" },
{ name: "week3", path: "oldsites/englishportfolio/week3" }
]
},
{
name: "esb-website",
folders: [],
sites: [
{ name: "esb-alumni-network", path: "oldsites/esb-website/esb-alumni-network" },
{ name: "esb-dan-1", path: "oldsites/esb-website/esb-dan-1" },
{ name: "esb-dan-2", path: "oldsites/esb-website/esb-dan-2" },
{ name: "esb-dan-broke", path: "oldsites/esb-website/esb-dan-broke" },
{ name: "esb-draft", path: "oldsites/esb-website/esb-draft" },
{ name: "esb-login-testing", path: "oldsites/esb-website/esb-login-testing" }
]
},
{
name: "personal-testing",
folders: [],
sites: [
{ name: "fancy-test", path: "oldsites/personal-testing/fancy-test" },
{ name: "personal1", path: "oldsites/personal-testing/personal1" },
{ name: "personal2", path: "oldsites/personal-testing/personal2" },
{ name: "personal3", path: "oldsites/personal-testing/personal3" }
]
}
],
sites: [
{ name: "brianzhou", path: "oldsites/brianzhou" },
{ name: "brianzhou2", path: "oldsites/brianzhou2" },
{ name: "brianzhou3", path: "oldsites/brianzhou3" },
{ name: "honeywell-testing", path: "oldsites/honeywell-testing" },
{ name: "john", path: "oldsites/john" }
]
},
{
name: "webapps",
folders: [
{
name: "learningtools",
folders: [],
sites: [
{ name: "3dmath", path: "webapps/learningtools/3dmath" },
{ name: "flash-flow-updated", path: "webapps/learningtools/flash-flow-updated" },
{ name: "flash-flow", path: "webapps/learningtools/flash-flow" }
]
}
],
sites: [
{ name: "aero-guide", path: "webapps/aero-guide" },
{ name: "login-testing", path: "webapps/login-testing" }
]
}
],
sites: []
};
/* ---------- RENDER ---------- */
function renderNode(node) {
const ul = document.createElement("ul");
ul.classList.add("collapsed");
// 📁 folders first
for (const folder of node.folders) {
const li = document.createElement("li");
const span = document.createElement("span");
span.textContent = folder.name;
span.className = "folder";
const subTree = renderNode(folder);
span.addEventListener("click", () => {
subTree.classList.toggle("collapsed");
});
li.appendChild(span);
li.appendChild(subTree);
ul.appendChild(li);
}
// 🌐 sites second
for (const site of node.sites) {
const li = document.createElement("li");
const a = document.createElement("a");
a.href = site.path + "/";
a.textContent = site.name;
a.className = "leaf";
li.appendChild(a);
ul.appendChild(li);
}
return ul;
}
/* ---------- INIT ---------- */
const tree = renderNode(TREE);
tree.classList.remove("collapsed");
container.appendChild(tree);