-
Notifications
You must be signed in to change notification settings - Fork 2
/
load.js
71 lines (64 loc) · 1.85 KB
/
load.js
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
// Load the links onto the main page
const sub = document.getElementById("sub");
const cstm = document.getElementById("custom");
const cntnr = document.getElementById("container");
function items(obj){
var ret = [];
for(v in obj){
ret.push([v, obj[v]]);
}
return ret;
}
function isDict(a) {
return a.constructor == Object;
}
function remove_punctucation(str) {
return [...str].filter(c => c == encodeURIComponent(c)).join("");
}
function recurse(dict, obj, pref="") {
let it = [...items(dict)];
console.log(it);
it.forEach(pair => {
let [a, b] = pair;
let det = document.createElement("details");
let sum = document.createElement("summary");
sum.innerHTML = a;
det.appendChild(sum);
if (!isDict(b)) {
let ul = document.createElement("ul");
b.forEach((s) => {
let newli = document.createElement("li");
newli.innerHTML =
`<a href="./sets/` + remove_punctucation(pref + a + s) + `">` + s + `</a>`;
ul.appendChild(newli);
});
det.appendChild(ul);
}
obj.appendChild(det);
console.log(a, b);
if (isDict(b)) {
recurse(b, det, pref + a);
}
});
}
recurse(LIST_OF_LANGS, cntnr);
/* OLD
LIST_OF_LINKS.forEach(([a, b]) => {
let det = document.createElement("details");
let sum = document.createElement("summary");
let [l, ...o] = a.split(" ");
sum.innerHTML = l + ` <i>` + o.join(" ") + `</i>`;
det.appendChild(sum);
let ul = document.createElement("ul");
b.forEach((s) => {
let newli = document.createElement("li");
newli.innerHTML =
`<a href="./sets/` + (a + s).replaceAll(" ", "") + `">` + s + `</a>`;
ul.appendChild(newli);
});
det.appendChild(ul);
document.body.insertBefore(det, cstm);
document.body.insertBefore(document.createElement("br"), cstm);
document.body.insertBefore(document.createElement("br"), cstm);
});
*/