-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
211 lines (180 loc) · 7.83 KB
/
main.js
File metadata and controls
211 lines (180 loc) · 7.83 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
import './style.css'
import dataFR from './metadata_fr.json';
import dataEN from './metadata_en.json';
window.addEventListener('DOMContentLoaded', () => {
// list all the entries in the data json
const keysFR = Object.keys(dataFR);
const keysEN = Object.keys(dataEN);
keysFR.forEach(key => {
// select the .page with the lang=fr attribute
let catContainer = document.querySelector(".page[lang=fr] ." + key);
let cat = dataFR[key];
console.log(key, typeof cat)
cat.forEach(item => {
if (typeof item === "string") {
let itemContainer = document.createElement("span");
itemContainer.classList.add("item");
itemContainer.innerText = item;
catContainer.appendChild(itemContainer);
return;
}
let itemContainer = document.createElement("div");
itemContainer.classList.add("item");
// HEADERS
if (item.name) {
let itemTitle = document.createElement("h3");
itemTitle.classList.add("name");
itemTitle.innerText = item.name;
itemContainer.appendChild(itemTitle);
}
if (item.company) {
let itemCompany = document.createElement("h3");
itemCompany.classList.add("company");
itemCompany.innerText = item.company;
itemContainer.appendChild(itemCompany);
}
if (item.institution) {
let itemInstitution = document.createElement("h3");
itemInstitution.classList.add("institution");
itemInstitution.innerText = item.institution;
itemContainer.appendChild(itemInstitution);
}
// SUBHEADERS
if (item.issuer) {
let itemIssuer = document.createElement("p");
itemIssuer.classList.add("issuer");
itemIssuer.innerText = item.issuer;
itemContainer.appendChild(itemIssuer);
}
if (item.title) {
let itemTitle = document.createElement("p");
itemTitle.classList.add("title");
itemTitle.innerText = item.title;
itemContainer.appendChild(itemTitle);
}
if (item.description) {
let itemDescription = document.createElement("p");
itemDescription.classList.add("description");
itemDescription.innerText = item.description;
itemContainer.appendChild(itemDescription);
}
if (item.position) {
let itemPosition = document.createElement("p");
itemPosition.classList.add("position");
itemPosition.innerText = item.position;
itemContainer.appendChild(itemPosition);
}
// ASIDE
if (item.date) {
let itemDate = document.createElement("p");
itemDate.classList.add("date");
itemDate.innerText = item.date;
itemContainer.appendChild(itemDate);
}
// OTHER
if (item.summary) {
let itemSummary = document.createElement("p");
itemSummary.classList.add("summary");
itemSummary.innerHTML = item.summary;
itemContainer.appendChild(itemSummary);
}
if (item.url) {
let itemUrl = document.createElement("a");
itemUrl.classList.add("url");
// for the inner text, use the url without the protocol and trailing slashes
itemUrl.innerText = "🔗 " + item.url.replace(/(^\w+:|^)\/\//, '').replace(/\/$/, "");
itemUrl.href = item.url;
itemUrl.target = "_blank";
itemContainer.appendChild(itemUrl);
}
// add the item container to the category container
catContainer.appendChild(itemContainer);
});
});
keysEN.forEach(key => {
// select the .page with the lang=fr attribute
let catContainer = document.querySelector(".page[lang=en] ." + key);
let cat = dataEN[key];
console.log(key, typeof cat)
cat.forEach(item => {
if (typeof item === "string") {
let itemContainer = document.createElement("span");
itemContainer.classList.add("item");
itemContainer.innerText = item;
catContainer.appendChild(itemContainer);
return;
}
let itemContainer = document.createElement("div");
itemContainer.classList.add("item");
// HEADERS
if (item.name) {
let itemTitle = document.createElement("h3");
itemTitle.classList.add("name");
itemTitle.innerText = item.name;
itemContainer.appendChild(itemTitle);
}
if (item.company) {
let itemCompany = document.createElement("h3");
itemCompany.classList.add("company");
itemCompany.innerText = item.company;
itemContainer.appendChild(itemCompany);
}
if (item.institution) {
let itemInstitution = document.createElement("h3");
itemInstitution.classList.add("institution");
itemInstitution.innerText = item.institution;
itemContainer.appendChild(itemInstitution);
}
// SUBHEADERS
if (item.issuer) {
let itemIssuer = document.createElement("p");
itemIssuer.classList.add("issuer");
itemIssuer.innerText = item.issuer;
itemContainer.appendChild(itemIssuer);
}
if (item.title) {
let itemTitle = document.createElement("p");
itemTitle.classList.add("title");
itemTitle.innerText = item.title;
itemContainer.appendChild(itemTitle);
}
if (item.description) {
let itemDescription = document.createElement("p");
itemDescription.classList.add("description");
itemDescription.innerText = item.description;
itemContainer.appendChild(itemDescription);
}
if (item.position) {
let itemPosition = document.createElement("p");
itemPosition.classList.add("position");
itemPosition.innerText = item.position;
itemContainer.appendChild(itemPosition);
}
// ASIDE
if (item.date) {
let itemDate = document.createElement("p");
itemDate.classList.add("date");
itemDate.innerText = item.date;
itemContainer.appendChild(itemDate);
}
// OTHER
if (item.summary) {
let itemSummary = document.createElement("p");
itemSummary.classList.add("summary");
itemSummary.innerHTML = item.summary;
itemContainer.appendChild(itemSummary);
}
if (item.url) {
let itemUrl = document.createElement("a");
itemUrl.classList.add("url");
// for the inner text, use the url without the protocol and trailing slashes
itemUrl.innerText = "🔗 " + item.url.replace(/(^\w+:|^)\/\//, '').replace(/\/$/, "");
itemUrl.href = item.url;
itemUrl.target = "_blank";
itemContainer.appendChild(itemUrl);
}
// add the item container to the category container
catContainer.appendChild(itemContainer);
});
});
});