-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
57 lines (51 loc) · 1.59 KB
/
utils.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
function addCss(src) {
document.querySelector(
"head"
).innerHTML += `<link rel="stylesheet" href="${src}" type="text/css" />`;
}
function addJS(src) {
const script = document.createElement("script");
script.setAttribute("src", src);
document.body.appendChild(script);
}
function buildHeader(templates) {
Promise.all(
templates.reverse().map((template) => {
return fetch(template)
.then((data) => data.text())
.then((content) => {
// const body = document.getElementById(url);
document.getElementsByTagName("body")[0].innerHTML =
content + document.getElementsByTagName("body")[0].innerHTML;
});
})
);
}
function buildFooter(templates) {
Promise.all(
templates.map((template) => {
return fetch(template)
.then((data) => data.text())
.then((content) => {
// const body = document.getElementById(url);
document.getElementsByTagName("body")[0].innerHTML += content;
});
})
);
}
function buildContent(templates) {
function fetchPage(url) {
// const placeholder = document.createElement('div');
// placeholder.id = url;
// document.getElementById('root').appendChild(placeholder);
return fetch(url)
.then((data) => data.text())
.then((content) => {
// const body = document.getElementById(url);
document.getElementById("root").innerHTML += content;
});
}
Promise.all(templates.map((template) => fetchPage(template))).then(() => {
addJS("/scripts/main.js");
});
}