forked from TusharKesarwani/Front-End-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
103 lines (81 loc) · 3.42 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
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
import projects from "./projects.js";
const urlParams = new URLSearchParams(window.location.search);
const searchQuery = urlParams.get('s');
let filteredProjects = (searchQuery && searchQuery != "") ? projects.filter((project) => project.title.toLowerCase().includes(searchQuery.toLowerCase())) : projects;
// displaying filtered projects
const projects_div = document.getElementsByClassName("projects")[0]
for (let project of filteredProjects) {
const project_div = document.createElement("div");
project_div.className="project";
const img = document.createElement("img")
img.src = project.img;
project_div.appendChild(img);
const project_info = document.createElement("div");
project_info.className = "project-info";
const heading = document.createElement("h2");
heading.innerHTML = project.title;
project_info.appendChild(heading);
const row = document.createElement("div");
row.className="row";
const tech = document.createElement("tech");
tech.className="tech";
for (let t of project.tags) {
const span = document.createElement("span");
span.innerHTML = t;
tech.appendChild(span);
}
row.appendChild(tech);
const links = document.createElement("div");
links.className = "links";
const project_link = document.createElement("a");
project_link.href = project['project-link'];
project_link.innerHTML = `<i class="fa-solid fa-link"></i>`;
project_link.target="_blank"
links.appendChild(project_link);
const github_link = document.createElement("a");
github_link.href = project['github-link'];
github_link.innerHTML = `<i class="fa-brands fa-github"></i>`;
github_link.target="_blank"
links.appendChild(github_link);
row.appendChild(links);
project_info.appendChild(row);
const desc = document.createElement('p');
desc.className="description";
desc.innerHTML=project.description;
project_info.appendChild(desc);
project_div.appendChild(project_info);
projects_div.appendChild(project_div);
}
// For search query form
if (searchQuery && searchQuery != "")
document.getElementById("search").value = searchQuery
const searchForm = document.getElementById("searchForm");
searchForm.addEventListener("submit",(e) => {
const searchText = document.getElementById("search");
e.preventDefault();
if (searchText.value == (searchQuery ? searchQuery : "")) {
return;
}
window.location = `/index.html?s=${searchText.value}`;
})
// For contributors list
fetch("https://api.github.com/repos/TusharKesarwani/Front-End-Projects/contributors?per_page=50", {
headers: {
'Authorization': ''
}
}).then(response => response.json())
.then(data => {
// Extract the data for each contributor
const contributors = data.map(contributor => ({
username: contributor.login,
avatarUrl: contributor.avatar_url,
profileUrl: contributor.html_url
}));
// Create and append HTML elements to display the contributors
const contributorsList = document.querySelector("#contributors-list");
contributors.forEach(contributor => {
const li = document.createElement("li");
li.innerHTML = `<a href="${contributor.profileUrl}"><img src="${contributor.avatarUrl}" alt="${contributor.username}"></a>`;
contributorsList.appendChild(li);
});
});