- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
Latest commit
114 lines (96 loc) · 4.09 KB
/
Copy pathscript.js
File metadata and controls
114 lines (96 loc) · 4.09 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
document.addEventListener("DOMContentLoaded",function(){
// Fetch repositories
fetchRepositories();
// Load learning entries
loadEntries();
// Add modal close handlers
setupModalHandlers();
});
functionsetupModalHandlers(){
constcloseButton=document.querySelector('.close-modal');
constmodal=document.getElementById('journal-modal');
if(closeButton){
closeButton.addEventListener('click',()=>{
modal.style.display='none';
});
}
// Close when clicking outside the modal
window.addEventListener('click',(event)=>{
if(event.target===modal){
modal.style.display='none';
}
});
}
// Dark mode styling
document.body.classList.add("dark-mode");
// Fetch GitHub repositories dynamically
asyncfunctionfetchRepositories(){
constusername="sameer-at-git";
constrepoList=document.getElementById("repo-list");
try{
constresponse=awaitfetch(`https://api.github.com/users/${username}/repos`);
constrepos=awaitresponse.json();
repos.forEach(repo=>{
letlistItem=document.createElement("li");
listItem.innerHTML=`<a href="${repo.html_url}" target="_blank">${repo.name}</a>`;
repoList.appendChild(listItem);
});
}catch(error){
console.error("Error fetching repositories: ",error);
}
}
asyncfunctionloadEntries(){
try{
constresponse=awaitfetch('entries.md');
if(!response.ok){
thrownewError(`HTTP error! status: ${response.status}`);
}
consttext=awaitresponse.text();
// Split the markdown into individual entries
constentries=text.split('\n# ').filter(entry=>entry.trim());
constentriesHTML=entries.map((entry,index)=>{
const[title, ...content]=(entry.startsWith('#') ? entry.substring(1) : entry).split('\n');
const[date,topic]=title.split(' - ');
// Get first paragraph for preview
constpreviewContent=content.join('\n').split('\n\n')[0];
return`
<div class="learning-entry" data-entry-id="${index}">
<div class="entry-header">
<h3>📅 Date: <span>${date}</span></h3>
<h4>🔖 Topic: <span>${topic}</span></h4>
</div>
<div class="entry-content">
${marked.parse(previewContent)}
<span class="read-more">Read More...</span>
</div>
</div>
`;
}).join('');
constcontainer=document.getElementById('entries-container');
if(container){
container.innerHTML=entriesHTML;
// Add click handlers to entries
document.querySelectorAll('.learning-entry').forEach((entry,index)=>{
entry.addEventListener('click',()=>{
const[title, ...content]=entries[index].split('\n');
const[date,topic]=title.split(' - ');
constmodalContent=`
<h2>${topic}</h2>
<h3>${date}</h3>
<div class="full-content">
${marked.parse(content.join('\n'))}
</div>
`;
document.getElementById('modal-content-container').innerHTML=modalContent;
document.getElementById('journal-modal').style.display='block';
});
});
}
}catch(error){
console.error('Error loading entries:',error);
document.getElementById('entries-container').innerHTML=
'<p style="color: red;">Error loading entries. Please make sure entries.md exists.</p>';
}
}
// Add marked.js library to your HTML file
// <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>