-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
146 lines (119 loc) · 5.34 KB
/
Copy pathscript.js
File metadata and controls
146 lines (119 loc) · 5.34 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
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
fetch('blogs/blogs.json')
.then(res => res.json())
.then(blogs => {
const container = document.getElementById('blog-list');
// Group blogs by category
const categories = {};
blogs.forEach(blog => {
if (!categories[blog.category]) {
categories[blog.category] = [];
}
categories[blog.category].push(blog);
});
// Render categories with expandable sections
for (const category in categories) {
const categorySection = document.createElement('div');
categorySection.classList.add('category-section');
// Header with arrow
const header = document.createElement('div');
header.classList.add('category-header');
header.innerHTML = `<h2>${category} <span class="arrow">▶</span></h2>`;
// Hidden blog list container
const blogList = document.createElement('div');
blogList.classList.add('blog-items');
blogList.style.display = "none";
categories[category].forEach(blog => {
const blogItem = document.createElement('div');
blogItem.innerHTML = `
<h3><a href="./blogs/${blog.path}">${blog.title}</a></h3>
<small>Date posted: ${blog.date}</small>
`;
blogList.appendChild(blogItem);
});
// Toggle expand/collapse
header.addEventListener('click', () => {
const isOpen = blogList.style.display === "block";
blogList.style.display = isOpen ? "none" : "block";
header.querySelector('.arrow').textContent = isOpen ? '▶' : '▼';
});
categorySection.appendChild(header);
categorySection.appendChild(blogList);
container.appendChild(categorySection);
}
})
.catch(err => console.error('Failed to load blogs:', err));
// Load personal info from data.json
fetch('data.json')
.then(res => res.json())
.then(data => {
document.getElementById('name').innerText = data.about.name;
document.getElementById('role').innerText = data.about.role;
const emailEl = document.getElementById('email');
emailEl.href = `mailto:${data.about.email}`;
emailEl.innerText = data.about.email;
data.skills.forEach(skill => {
const li = document.createElement('li');
li.textContent = skill;
document.getElementById('skills-list').appendChild(li);
});
data.education.forEach(edu => {
const div = document.createElement('div');
div.classList.add('education-item');
div.innerHTML = `
<div class="edu-main">
<span class="edu-degree">${edu.degree}</span>
<span class="edu-year">${edu.year}</span>
</div>
<div class="edu-institute">${edu.institute}</div>
`;
document.getElementById('education-list').appendChild(div);
});
data.experience.forEach(exp => {
const div = document.createElement('div');
div.classList.add('experience-item');
div.innerHTML = `
<div class="exp-main">
<span class="exp-role">${exp.role}</span>
<span class="exp-duration">${exp.duration}</span>
</div>
<div class="exp-company">${exp.company}</div>
`;
document.getElementById('experience-list').appendChild(div);
});
for (const [platform, link] of Object.entries(data.socials)) {
const li = document.createElement('li');
li.innerHTML = `<a href="${link}" target="_blank">${platform}</a>`;
document.getElementById('socials-list').appendChild(li);
}
});
// Dynamically load GitHub Repositories
const GITHUB_USERNAME = 'AvinashYerra';
fetch(`https://api.github.com/users/${GITHUB_USERNAME}/repos`)
.then(res => res.json())
.then(repos => {
const projectsContainer = document.getElementById('projects-list');
const filteredRepos = repos.filter(repo => !repo.fork)
.sort((a, b) => new Date(b.updated_at) - new Date(a.updated_at))
.slice(0,5);
filteredRepos.forEach(repo => {
const li = document.createElement('li');
// li.innerHTML = `<strong>${repo.name}</strong>: ${repo.description || 'No description'} - <a href="${repo.html_url}" target="_blank">View on GitHub</a>`;
li.innerHTML = `<strong>${repo.name}</strong> - <a href="${repo.html_url}" target="_blank">View on GitHub</a>`;
projectsContainer.appendChild(li);
});
})
.catch(err => console.error('Failed to fetch GitHub repos:', err));
// DARK / LIGHT MODE
const toggleBtn = document.getElementById("theme-toggle");
// load saved mode
const savedTheme = localStorage.getItem("theme");
if (savedTheme === "dark") {
document.body.classList.add("dark");
toggleBtn.textContent = "☀️";
}
toggleBtn.addEventListener("click", () => {
document.body.classList.toggle("dark");
const isDark = document.body.classList.contains("dark");
toggleBtn.textContent = isDark ? "☀️" : "🌙";
localStorage.setItem("theme", isDark ? "dark" : "light");
});