-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabout_me_import.js
More file actions
43 lines (34 loc) · 1.28 KB
/
Copy pathabout_me_import.js
File metadata and controls
43 lines (34 loc) · 1.28 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
fetch('about_me.json')
.then(response => response.json())
.then(data => {
//populate contents list
const contentsContainer = document.querySelector('#contents-list');
if (contentsContainer)
{
data.sections.forEach(section => {
const contentsElement = document.createElement('li');
contentsElement.innerHTML = `<a href="#${section.scrollID}">${section.title}</a>`;
contentsContainer.appendChild(contentsElement);
});
}
else
{
console.log('No element found with selector "#contents-menu"');
}
//Populate page body
const bodyContainer = document.querySelector('#about-content');
if (bodyContainer)
{
data.sections.forEach(section => {
const bodyElement = document.createElement('div');
paragraphInfo = `<h1 id="${section.scrollID}">${section.title}</h1>
<p>${section.body}</p>`;
bodyElement.innerHTML = paragraphInfo;
bodyContainer.appendChild(bodyElement);
});
}
else
{
console.log('No element found with selector "#about-content"')
}
});