-
Notifications
You must be signed in to change notification settings - Fork 365
/
index.js
488 lines (405 loc) · 14.7 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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
import {
bio,
skills,
projects,
education,
experience,
footer,
} from "./data.js";
import { URLs } from './user-data/urls.js';
const { webProjects, softwareProjects, androidProjects, freelanceProjects } =
projects;
const { medium, gitConnected } = URLs;
/**
* Fetches blogs from Medium profile.
*
* @function
* @async
*
* @throws {Error} If there is any error in fetching the blogs from Medium profile.
*
* @returns {void}
*/
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 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;
}
/**
* Populates bio to the HTML page.
*
* @function
*
* @param {Array} items - An array of objects that contain bio information.
* @param {string} id - The id of the HTML element to which bio will be appended.
*
* @returns {void}
*/
function populateBio(items, id) {
const bioTag = document.getElementById(id);
items.forEach((bioItem) => {
const p = getElement("p", null);
p.innerHTML = bioItem;
bioTag.append(p);
});
}
/**
* Populates skills to the HTML page.
*
* @function
*
* @param {Array} items - An array of objects that contain skill information.
* @param {string} id - The id of the HTML element to which skills will be appended.
*
* @returns {void}
*/
function populateSkills(items, id) {
const skillsTag = document.getElementById(id);
items.forEach(({ skillName, color, percentage }) => {
const h3 = getElement("h3", null);
h3.innerHTML = skillName;
const divProgress = getElement("div", "progress");
const divProgressBar = getElement("div", `progress-bar color-${color}`);
divProgressBar.style = `width: ${percentage}%`;
divProgress.append(divProgressBar);
const divProgressWrap = getElement("div", "progress-wrap");
divProgressWrap.append(h3, divProgress);
const divAnimateBox = getElement("div", "col-md-6 animate-box");
divAnimateBox.append(divProgressWrap);
skillsTag.append(divAnimateBox);
});
}
/**
* Populates projects to the HTML page.
*
* @function
*
* @param {Array} items - An array of objects that contain project information.
* @param {string} id - The id of the HTML element to which projects will be appended.
*
* @returns {void}
*/
function populateProjects(items, id) {
let projectdesign = document.getElementById(id);
let h4 = document.createElement("h4");
h4.className = "project-heading";
let a = document.createElement("a");
a.target = "_blank";
let img = document.createElement("img");
img.className = "img-fluid";
let divResumeContentLeft = document.createElement("div");
divResumeContentLeft.className = "resume-content";
divResumeContentLeft.id = "left-div";
divResumeContentLeft.append(img);
let divResumeContentRight = document.createElement("div");
divResumeContentRight.className = "resume-content";
divResumeContentRight.id = "right-div";
let p = document.createElement("p");
p.className = "project-description";
let divSpan = document.createElement("div");
let divSubHeading = document.createElement("div");
divSubHeading.className = "sub-heading";
divSubHeading.append(p);
divSubHeading.append(divSpan);
divResumeContentRight.append(divSubHeading);
let divResumeItem = document.createElement("div");
divResumeItem.className = "resume-item";
divResumeItem.append(divResumeContentLeft);
divResumeItem.append(divResumeContentRight);
a.append(divResumeItem);
let divProjectCard = document.createElement("div");
divProjectCard.className = "project-card";
divProjectCard.append(a);
let li = document.createElement("li");
li.append(divProjectCard);
let hr = document.createElement("hr");
for (let i = 0; i < items.length; i++) {
h4.innerHTML = items[i].projectName;
a.href = items[i].preview;
img.src = items[i].image;
p.innerHTML = items[i].summary;
divSpan.innerHTML = "";
for (let k = 0; k < items[i].techStack.length; k++) {
let span = document.createElement("span");
span.className = "badge badge-secondary";
span.innerHTML = items[i].techStack[k];
divSpan.append(span);
}
projectdesign.append(li.cloneNode(true));
if (i != items.length - 1) {
projectdesign.append(hr.cloneNode(true));
}
}
}
/**
* Creates and populates a list of blog posts with specified properties
*
* @function
*
* @param {Array} items - An array of objects, each representing a blog post
* @param {string} id - The ID of the parent element where the list of posts will be appended
*
* @returns {undefined}
*/
function populateBlogs(items, id) {
const projectdesign = document.getElementById(id);
const count = 3;
for (let i = 0; i < count; i++) {
const h4 = document.createElement("h4");
h4.className = "project-heading";
h4.innerHTML = items[i].title;
const a = document.createElement("a");
a.href = items[i].link;
a.target = "_blank";
a.append(h4);
const pubDateEle = document.createElement('p');
pubDateEle.className = 'publish-date';
pubDateEle.innerHTML = getBlogDate(items[i].pubDate);
a.append(pubDateEle);
const divResumeContentRight = document.createElement("div");
divResumeContentRight.className = "resume-content";
divResumeContentRight.id = "right-div";
const p = document.createElement("p");
p.className = "project-description";
const html = items[i].content;
const [, doc] = /<p>(.*?)<\/p>/g.exec(html) || [];
p.innerHTML = doc;
const divSpan = document.createElement("div");
for (const category of items[i].categories) {
const span = document.createElement("span");
span.className = "badge badge-secondary";
span.innerHTML = category;
divSpan.append(span);
}
const divSubHeading = document.createElement("div");
divSubHeading.className = "sub-heading";
divSubHeading.append(p, divSpan);
divResumeContentRight.append(divSubHeading);
const divResumeItem = document.createElement("div");
divResumeItem.className = "resume-item";
divResumeItem.append(divResumeContentRight);
a.append(divResumeItem);
const divProjectCard = document.createElement("div");
divProjectCard.className = "project-card";
divProjectCard.append(a);
const li = document.createElement("li");
li.append(divProjectCard);
projectdesign.append(li);
if (i !== count - 1) {
projectdesign.append(document.createElement("hr"));
}
}
}
/**
* Populate the HTML timeline with items.
* @param {Array} items - An array of objects that represent the timeline items.
* @param {string} id - The id of the main container element in the HTML.
* @property {string} items[].subtitle - The subtitle of the timeline item.
* @property {string} items[].duration - The duration of the timeline item.
* @property {string} items[].title - The title of the timeline item.
* @property {Array} items[].details - An array of details for the timeline item.
* @property {Array} items[].tags - An array of tags for the timeline item.
* @property {string} items[].icon - The name of the font awesome icon to use.
*/
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 badge-secondary";
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);
}
/**
* Populate links in the specified footer section with provided data.
*
* @param {Array} items - Array of objects containing data for links
* @param {String} id - Id of the footer section in which the links will be populated
*
* @return {undefined}
*/
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);
}
});
}
/**
* Creates a new element with specified tag name and class name.
*
* @param {string} tagName - The tag name of the element.
* @param {string} className - The class name of the element.
*
* @return {HTMLElement} The newly created element.
*/
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);
fetchGitConnectedData(gitConnected);
populateProjects(webProjects, "web-projects");
populateProjects(softwareProjects, "software-projects");
populateProjects(androidProjects, "android-projects");
populateProjects(freelanceProjects, "freelance-projects");
populateExp_Edu(experience, "experience");
populateExp_Edu(education, "education");
populateLinks(footer, "footer");