-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
45 lines (37 loc) · 1.17 KB
/
script.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
const projectContainer = document.getElementById('projects-container');
const fetchProjects = async () => {
try {
const res = await fetch('projects.json');
const data = await res.json();
data.forEach(createProjectCard);
} catch (error) {
console.error('Error fetching projects:', error);
}
};
const createProjectCard = (project) => {
const projectEl = createProjectElement(project);
appendProjectElement(projectEl);
};
const createProjectElement = (project) => {
const { id, name, location, image, reusable, url } = project;
const projectEl = document.createElement('div');
projectEl.classList.add('project');
const projectInnerHTML = `
<div class="img-container">
<img src="${image}" alt="Image Preview" />
</div>
<div class="info">
<h3>${name}</h3>
<p><a href="${url}" target="_blank">Review</a></p>
</div>
<button>
<a href="./projects/${id}.${location}/index.html" class="href" target="_blank">Go to the project</a>
</button>
`;
projectEl.innerHTML = projectInnerHTML;
return projectEl;
};
const appendProjectElement = (projectEl) => {
projectContainer.appendChild(projectEl);
};
fetchProjects();