Skip to content

Commit 3ceb14e

Browse files
committed
Fix alone handle
1 parent fe8ef82 commit 3ceb14e

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

docs/js/github-profiles.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ document.addEventListener('DOMContentLoaded', function() {
1010
if (text.startsWith('@')) {
1111
const username = text.substring(1);
1212
if (username && username.length > 0) {
13-
// Just use the span without displaying the handle again (will be shown in card)
14-
cell.innerHTML = `<span class="github-handle" data-username="${username}"></span>`;
13+
// Replace the entire cell content with a span to avoid the @ appearing alone
14+
cell.innerHTML = `<span class="github-handle-wrapper"><span class="github-handle" data-username="${username}"></span></span>`;
1515
}
1616
}
1717
});
@@ -23,7 +23,8 @@ document.addEventListener('DOMContentLoaded', function() {
2323
elements.forEach(function(element) {
2424
// Skip elements that are within profile cards (to avoid reprocessing)
2525
if (element.closest('.github-profile-card') ||
26-
element.closest('.profile-card')) {
26+
element.closest('.profile-card') ||
27+
element.closest('.github-handle-wrapper')) {
2728
return;
2829
}
2930

@@ -36,9 +37,10 @@ document.addEventListener('DOMContentLoaded', function() {
3637
// Not preceded by text that would make it an email
3738
const pattern = /(^|\s)@([a-zA-Z0-9-]+)(?!\S*@)/g;
3839

39-
// Replace all instances of GitHub handles with profile cards
40+
// Replace all instances of GitHub handles with profile cards - completely replace the match
4041
element.innerHTML = text.replace(pattern, function(match, prefix, username) {
41-
return `${prefix}<span class="github-handle" data-username="${username}"></span>`;
42+
// Include the prefix (space) in the wrapper to avoid orphaned @ symbols
43+
return `<span class="github-handle-wrapper">${prefix}<span class="github-handle" data-username="${username}"></span></span>`;
4244
});
4345
});
4446

@@ -56,8 +58,13 @@ document.addEventListener('DOMContentLoaded', function() {
5658
// Add loading indicator
5759
cardContainer.innerHTML = `<div class="loading">Loading GitHub profile...</div>`;
5860

59-
// Insert card after the handle
60-
handle.parentNode.insertBefore(cardContainer, handle.nextSibling);
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);
65+
} else {
66+
handle.parentNode.insertBefore(cardContainer, handle.nextSibling);
67+
}
6168

6269
// Fetch GitHub profile data
6370
const headers = {
@@ -93,6 +100,11 @@ document.addEventListener('DOMContentLoaded', function() {
93100
</div>
94101
</div>
95102
`;
103+
104+
// Once the profile is loaded, we can safely hide the handle wrapper
105+
if (handleWrapper) {
106+
handleWrapper.style.display = 'none';
107+
}
96108
})
97109
.catch(error => {
98110
// If fetching fails, just show a simple link

0 commit comments

Comments
 (0)