Skip to content

Commit 8a50d40

Browse files
committed
Fix compact authors
1 parent 3ceb14e commit 8a50d40

1 file changed

Lines changed: 96 additions & 13 deletions

File tree

docs/js/github-profiles.js

Lines changed: 96 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
document.addEventListener('DOMContentLoaded', function() {
33
// Process GitHub handles in any element
44
const processGitHubHandles = function() {
5+
// Create a container for all profile cards if multiple are present
6+
const mainContainer = document.createElement('div');
7+
mainContainer.className = 'github-profiles-container';
8+
let profilesAdded = 0;
9+
let currentRow = null;
10+
511
// Special handling for table cells with GitHub handles
612
const tableCells = document.querySelectorAll('td');
713
tableCells.forEach(function(cell) {
@@ -24,7 +30,8 @@ document.addEventListener('DOMContentLoaded', function() {
2430
// Skip elements that are within profile cards (to avoid reprocessing)
2531
if (element.closest('.github-profile-card') ||
2632
element.closest('.profile-card') ||
27-
element.closest('.github-handle-wrapper')) {
33+
element.closest('.github-handle-wrapper') ||
34+
element.closest('.github-profiles-container')) {
2835
return;
2936
}
3037

@@ -44,9 +51,20 @@ document.addEventListener('DOMContentLoaded', function() {
4451
});
4552
});
4653

47-
// Now process all the handles we've wrapped
54+
// Count total handle instances to decide on layout
4855
const githubHandles = document.querySelectorAll('.github-handle');
56+
const totalHandles = githubHandles.length;
4957

58+
// If we have multiple handles, append the container to the document body
59+
// and prepare for a grid layout
60+
if (totalHandles > 1) {
61+
document.body.appendChild(mainContainer);
62+
currentRow = document.createElement('div');
63+
currentRow.className = 'github-profiles-row';
64+
mainContainer.appendChild(currentRow);
65+
}
66+
67+
// Now process all the handles we've wrapped
5068
githubHandles.forEach(function(handle) {
5169
const username = handle.getAttribute('data-username');
5270
if (!username) return;
@@ -58,12 +76,30 @@ document.addEventListener('DOMContentLoaded', function() {
5876
// Add loading indicator
5977
cardContainer.innerHTML = `<div class="loading">Loading GitHub profile...</div>`;
6078

61-
// Insert card after the handle wrapper, not just the handle
62-
const handleWrapper = handle.closest('.github-handle-wrapper');
63-
if (handleWrapper) {
64-
handleWrapper.parentNode.insertBefore(cardContainer, handleWrapper.nextSibling);
79+
// If multiple handles exist, add to the grid container
80+
if (totalHandles > 1) {
81+
if (profilesAdded > 0 && profilesAdded % 3 === 0) {
82+
// Create a new row every 3 profiles
83+
currentRow = document.createElement('div');
84+
currentRow.className = 'github-profiles-row';
85+
mainContainer.appendChild(currentRow);
86+
}
87+
currentRow.appendChild(cardContainer);
88+
profilesAdded++;
89+
90+
// Hide the original handle wrapper
91+
const handleWrapper = handle.closest('.github-handle-wrapper');
92+
if (handleWrapper) {
93+
handleWrapper.style.display = 'none';
94+
}
6595
} else {
66-
handle.parentNode.insertBefore(cardContainer, handle.nextSibling);
96+
// Insert card after the handle wrapper for single profile case
97+
const handleWrapper = handle.closest('.github-handle-wrapper');
98+
if (handleWrapper) {
99+
handleWrapper.parentNode.insertBefore(cardContainer, handleWrapper.nextSibling);
100+
} else {
101+
handle.parentNode.insertBefore(cardContainer, handle.nextSibling);
102+
}
67103
}
68104

69105
// Fetch GitHub profile data
@@ -101,9 +137,12 @@ document.addEventListener('DOMContentLoaded', function() {
101137
</div>
102138
`;
103139

104-
// Once the profile is loaded, we can safely hide the handle wrapper
105-
if (handleWrapper) {
106-
handleWrapper.style.display = 'none';
140+
// For single profile case, hide the original handle wrapper
141+
if (totalHandles === 1) {
142+
const handleWrapper = handle.closest('.github-handle-wrapper');
143+
if (handleWrapper) {
144+
handleWrapper.style.display = 'none';
145+
}
107146
}
108147
})
109148
.catch(error => {
@@ -112,21 +151,45 @@ document.addEventListener('DOMContentLoaded', function() {
112151
console.error('Error fetching GitHub profile:', error);
113152
});
114153
});
154+
155+
// If we added profiles to the grid, position it properly on the page
156+
if (profilesAdded > 0) {
157+
// Find a good location to insert the grid (near the first handle)
158+
const firstHandleWrapper = document.querySelector('.github-handle-wrapper');
159+
if (firstHandleWrapper && firstHandleWrapper.parentNode) {
160+
// Move from body to proper location in document
161+
document.body.removeChild(mainContainer);
162+
firstHandleWrapper.parentNode.insertBefore(mainContainer, firstHandleWrapper.nextSibling);
163+
}
164+
}
115165
};
116166

117167
// Add CSS for GitHub profiles
118168
const style = document.createElement('style');
119169
style.textContent = `
170+
.github-profiles-container {
171+
margin: 20px 0;
172+
max-width: 100%;
173+
}
174+
.github-profiles-row {
175+
display: flex;
176+
flex-wrap: wrap;
177+
gap: 10px;
178+
margin-bottom: 10px;
179+
}
120180
.github-profile-card {
121-
margin: 10px 0;
181+
margin: 5px 0;
182+
flex: 1 1 calc(33.333% - 10px);
183+
min-width: 200px;
184+
max-width: calc(33.333% - 10px);
122185
}
123186
.profile-card {
124187
display: flex;
125188
border: 1px solid #e1e4e8;
126189
border-radius: 6px;
127190
padding: 10px;
128191
background-color: #f6f8fa;
129-
max-width: 400px;
192+
height: 100%;
130193
}
131194
.profile-image img {
132195
width: 50px;
@@ -136,6 +199,7 @@ document.addEventListener('DOMContentLoaded', function() {
136199
}
137200
.profile-info h4 {
138201
margin: 0 0 5px 0;
202+
font-size: 0.95em;
139203
}
140204
.profile-info .username {
141205
margin: 0 0 5px 0;
@@ -144,14 +208,33 @@ document.addEventListener('DOMContentLoaded', function() {
144208
}
145209
.profile-info .bio {
146210
margin: 5px 0 0 0;
147-
font-size: 0.9em;
211+
font-size: 0.85em;
148212
color: #586069;
213+
display: -webkit-box;
214+
-webkit-line-clamp: 2;
215+
-webkit-box-orient: vertical;
216+
overflow: hidden;
217+
text-overflow: ellipsis;
149218
}
150219
.loading {
151220
font-style: italic;
152221
color: #586069;
153222
font-size: 0.9em;
154223
}
224+
225+
/* Responsive adjustments */
226+
@media (max-width: 768px) {
227+
.github-profile-card {
228+
flex: 1 1 calc(50% - 10px);
229+
max-width: calc(50% - 10px);
230+
}
231+
}
232+
@media (max-width: 480px) {
233+
.github-profile-card {
234+
flex: 1 1 100%;
235+
max-width: 100%;
236+
}
237+
}
155238
`;
156239
document.head.appendChild(style);
157240

0 commit comments

Comments
 (0)