-
Notifications
You must be signed in to change notification settings - Fork 381
/
Copy pathindex.js
458 lines (386 loc) · 13.8 KB
/
index.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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
import {
bio,
skills,
education,
experience,
trekking,
footer,
} from "./user-data/data.js";
import { URLs } from "./user-data/urls.js";
const { medium, gitConnected, gitRepo } = URLs;
async function fetchBlogsFromMedium(url) {
try {
const response = await fetch(url);
const { items } = await response.json();
populateBlogs(items, "blogs");
} catch (error) {
throw new Error(
`Error in fetching the blogs from Medium profile: ${error}`
);
}
}
async function fetchReposFromGit(url) {
try {
const response = await fetch(url);
const items = await response.json();
populateRepo(items, "repos");
} catch (error) {
throw new Error(`Error in fetching the blogs from repos: ${error}`);
}
}
async function fetchGitConnectedData(url) {
try {
const response = await fetch(url);
console.log(response);
const { basics } = await response.json();
// populateBlogs(items, "blogs");
mapBasicResponse(basics);
} catch (error) {
throw new Error(`Error in fetching the blogs from git connected: ${error}`);
}
}
function mapBasicResponse(basics) {
const {
name,
label,
image,
email,
phone,
url,
summary,
profiles,
headline,
blog,
yearsOfExperience,
username,
locationAsString,
region,
karma,
id,
followers,
following,
picture,
website,
} = basics;
// added title of page
window.parent.document.title = name;
}
function populateBio(items, id) {
const bioTag = document.getElementById(id);
items.forEach((bioItem) => {
const p = getElement("p", null);
p.innerHTML = bioItem;
bioTag.append(p);
});
}
function populateSkills(items, id) {
const skillsTag = document.getElementById(id);
items.forEach((item) => {
const h3 = getElement("li", null);
h3.innerHTML = item;
const divProgressWrap = getElement("div", "progress-wrap");
divProgressWrap.append(h3);
const divAnimateBox = getElement("div", "col-md-12 animate-box");
divAnimateBox.append(divProgressWrap);
skillsTag.append(divAnimateBox);
});
}
function populateTrekking(items) {
const skillsTag = document.getElementById('trekking');
items.forEach((item) => {
const h3 = getElement("li", null);
h3.innerHTML = item;
const divProgressWrap = getElement("div", "progress-wrap");
divProgressWrap.append(h3);
const divAnimateBox = getElement("div", "col-md-12 animate-box");
divAnimateBox.append(divProgressWrap);
skillsTag.append(divAnimateBox);
});
}
function populateBlogs(items, id) {
const projectdesign = document.getElementById(id);
const count = 3; // Number of blogs to display
for (let i = 0; i < count; i++) {
// Create a wrapper for the blog card
const blogCard = document.createElement("div");
blogCard.className = "blog-card";
blogCard.style = `
display: flex;
flex-direction: column;
border-radius: 12px;
padding: 16px;
font-size: 14px;
background: linear-gradient(135deg, rgb(255, 221, 153), rgb(249, 191, 63));
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
min-height: 150px;
cursor: pointer;
`;
// Wrap the card content in an anchor tag
const blogLink = document.createElement("a");
blogLink.href = items[i].link;
blogLink.target = "_blank";
blogLink.style = "text-decoration: none; color: black; display: block;";
blogCard.appendChild(blogLink);
// Blog Title
const blogTitle = document.createElement("h4");
blogTitle.className = "blog-heading";
blogTitle.innerHTML = items[i].title;
blogTitle.style = "margin: 0 0 8px; font-size: 18px; font-weight: bold;";
blogLink.appendChild(blogTitle);
// Publish Date
const pubDateEle = document.createElement("p");
pubDateEle.className = "publish-date";
pubDateEle.innerHTML = getBlogDate(items[i].pubDate);
pubDateEle.style = "margin: 0 0 12px; font-size: 12px; color: #555;";
blogLink.appendChild(pubDateEle);
// Blog Description
const blogDescription = document.createElement("p");
blogDescription.className = "blog-description";
const html = items[i].content;
const [, doc] = /<p>(.*?)<\/p>/g.exec(html) || [];
blogDescription.innerHTML = doc;
blogDescription.style = "margin: 0 0 12px; font-size: 12px; color: #666;";
blogLink.appendChild(blogDescription);
// Categories (Tags)
const categoriesDiv = document.createElement("div");
categoriesDiv.style = "display: flex; gap: 8px; margin-top: 12px;";
for (const category of items[i].categories) {
const badge = document.createElement("span");
badge.className = "badge";
badge.innerHTML = category;
badge.style = `
font-size: 12px;
padding: 4px 8px;
background-color: #007acc;
color: white;
border-radius: 4px;
`;
categoriesDiv.appendChild(badge);
}
blogLink.appendChild(categoriesDiv);
// Append the blog card to the container
projectdesign.appendChild(blogCard);
}
}
function populateRepo(items, id) {
const projectdesign = document.getElementById(id);
const count = 4; // Adjust this count based on the number of repos you want to display
// Set up a wrapper div to hold repo cards in rows of 2
const rowWrapper = document.createElement("div");
rowWrapper.style =
"display: flex; flex-wrap: wrap; gap: 16px; justify-content: space-between;";
projectdesign.appendChild(rowWrapper);
for (let i = 0; i < count; i++) {
// Create elements for each repo card
const repoCard = document.createElement("div");
repoCard.className = "repo-card";
repoCard.style = `
flex: 1 0 48%; /* Two cards in one row */
display: flex;
flex-direction: column;
justify-content: space-between;
border-radius: 12px;
padding: 16px;
font-size: 14px;
background: linear-gradient(135deg, #ffdd99, #f9bf3f);
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
transition: transform 0.2s ease-in-out;
cursor: pointer;
`;
// Make the card clickable by wrapping the content inside an anchor tag
const repoLink = document.createElement("a");
repoLink.href = `https://github.com/${items[i].author}/${items[i].name}`;
repoLink.target = "_blank";
repoLink.style =
"text-decoration: none; color: black; display: block; height: 100%;";
repoCard.appendChild(repoLink);
// Repository name
const repoName = document.createElement("h4");
repoName.className = "repo-heading";
repoName.innerHTML = items[i].name;
repoName.style = "margin: 0; font-size: 18px; font-weight: bold;";
repoLink.appendChild(repoName);
// Repository description
const repoDescription = document.createElement("p");
repoDescription.className = "repo-description";
repoDescription.innerHTML = items[i].description;
repoDescription.style = "margin-top: 8px; font-size: 12px; color: #555;";
repoLink.appendChild(repoDescription);
// Stats row (Language, Stars, Forks)
const statsRow = document.createElement("div");
statsRow.style = `
display: flex;
align-items: center;
gap: 16px;
margin-top: 12px;
font-size: 12px;
color: #666;
`;
// Language
const languageDiv = document.createElement("div");
languageDiv.style = "display: flex; align-items: center; gap: 4px;";
languageDiv.innerHTML = `
<span style="width: 8px; height: 8px; background-color: #666; border-radius: 50%; display: inline-block;"></span>
${items[i].language}
`;
statsRow.appendChild(languageDiv);
// Stars
const starsDiv = document.createElement("div");
starsDiv.style = "display: flex; align-items: center; gap: 4px;";
starsDiv.innerHTML = `
<img src="https://img.icons8.com/ios-filled/16/666666/star--v1.png" alt="Stars">
${items[i].stars}
`;
statsRow.appendChild(starsDiv);
// Forks
const forksDiv = document.createElement("div");
forksDiv.style = "display: flex; align-items: center; gap: 4px;";
forksDiv.innerHTML = `
<img src="https://img.icons8.com/ios-filled/16/666666/code-fork.png" alt="Forks">
${items[i].forks}
`;
statsRow.appendChild(forksDiv);
repoLink.appendChild(statsRow);
// Add the repo card to the row wrapper
rowWrapper.appendChild(repoCard);
}
}
function populateExp_Edu(items, id) {
let mainContainer = document.getElementById(id);
for (let i = 0; i < items.length; i++) {
let spanTimelineSublabel = document.createElement("span");
spanTimelineSublabel.className = "timeline-sublabel";
spanTimelineSublabel.innerHTML = items[i].subtitle;
let spanh2 = document.createElement("span");
spanh2.innerHTML = items[i].duration;
let h2TimelineLabel = document.createElement("h2");
h2TimelineLabel.innerHTML = items[i].title;
h2TimelineLabel.append(spanh2);
let divTimelineLabel = document.createElement("div");
divTimelineLabel.className = "timeline-label";
divTimelineLabel.append(h2TimelineLabel);
divTimelineLabel.append(spanTimelineSublabel);
for (let j = 0; j < items[i].details.length; j++) {
let pTimelineText = document.createElement("p");
pTimelineText.className = "timeline-text";
pTimelineText.innerHTML = "▪ " + items[i].details[j];
divTimelineLabel.append(pTimelineText);
}
let divTags = document.createElement("div");
for (let j = 0; j < items[i].tags.length; j++) {
let spanTags = document.createElement("span");
spanTags.className = "badge";
spanTags.innerHTML = items[i].tags[j];
divTags.append(spanTags);
}
divTimelineLabel.append(divTags);
let iFa = document.createElement("i");
iFa.className = "fa fa-" + items[i].icon;
let divTimelineIcon = document.createElement("div");
divTimelineIcon.className = "timeline-icon color-2";
divTimelineIcon.append(iFa);
let divTimelineEntryInner = document.createElement("div");
divTimelineEntryInner.className = "timeline-entry-inner";
divTimelineEntryInner.append(divTimelineIcon);
divTimelineEntryInner.append(divTimelineLabel);
let article = document.createElement("article");
article.className = "timeline-entry animate-box";
article.append(divTimelineEntryInner);
mainContainer.append(article);
}
let divTimelineIcon = document.createElement("div");
divTimelineIcon.className = "timeline-icon color-2";
let divTimelineEntryInner = document.createElement("div");
divTimelineEntryInner.className = "timeline-entry-inner";
divTimelineEntryInner.append(divTimelineIcon);
let article = document.createElement("article");
article.className = "timeline-entry begin animate-box";
article.append(divTimelineEntryInner);
mainContainer.append(article);
}
function populateLinks(items, id) {
let footer = document.getElementById(id);
items.forEach(function (item) {
if (item.label !== "copyright-text") {
let span = document.createElement("span");
span.className = "col";
let p = document.createElement("p");
p.className = "col-title";
p.innerHTML = item.label;
span.append(p);
let nav = document.createElement("nav");
nav.className = "col-list";
let ul = document.createElement("ul");
item.data.forEach(function (data) {
let li = document.createElement("li");
let a = document.createElement("a");
if (data.link) {
a.href = data.link;
a.target = "_blank";
}
if (data.func) {
a.setAttribute("onclick", data.func);
}
a.innerHTML = data.text;
li.append(a);
ul.append(li);
});
nav.append(ul);
span.append(nav);
footer.append(span);
}
if (item.label === "copyright-text") {
let div = document.createElement("div");
div.className = "copyright-text no-print";
item.data.forEach(function (copyright) {
let p = document.createElement("p");
p.innerHTML = copyright;
div.append(p);
});
footer.append(div);
}
});
}
function getElement(tagName, className) {
let item = document.createElement(tagName);
item.className = className;
return item;
}
function getBlogDate(publishDate) {
const elapsed = Date.now() - Date.parse(publishDate);
// Time conversions in milliseconds
const msPerSecond = 1000;
const msPerMinute = msPerSecond * 60;
const msPerHour = msPerMinute * 60;
const msPerDay = msPerHour * 24;
const msPerMonth = msPerDay * 30;
const msPerYear = msPerDay * 365;
if (elapsed < msPerMinute) {
const seconds = Math.floor(elapsed / msPerSecond);
return `${seconds} seconds ago`;
} else if (elapsed < msPerHour) {
const minutes = Math.floor(elapsed / msPerMinute);
return `${minutes} minutes ago`;
} else if (elapsed < msPerDay) {
const hours = Math.floor(elapsed / msPerHour);
return `${hours} hours ago`;
} else if (elapsed < msPerMonth) {
const days = Math.floor(elapsed / msPerDay);
return days == 1 ? `${days} day ago` : `${days} days ago`;
} else if (elapsed < msPerYear) {
const months = Math.floor(elapsed / msPerMonth);
return months == 1 ? `${months} month ago` : `${months} months ago`;
} else {
const years = Math.floor(elapsed / msPerYear);
return years == 1 ? `${years} year ago` : `${years} years ago`;
}
}
populateBio(bio, "bio");
populateSkills(skills, "skills");
fetchBlogsFromMedium(medium);
fetchReposFromGit(gitRepo);
fetchGitConnectedData(gitConnected);
populateExp_Edu(experience, "experience");
populateTrekking(trekking);
populateExp_Edu(education, "education");
populateLinks(footer, "footer");