Skip to content

Commit 55e4d56

Browse files
committed
add anchor links to all headlines
now behind each headline (h2, h3....) appears a small # character linking to this specific headline. makes it easier to copy paste deeplinks to certain sections / headlines e.g. when you share a link in a forum. Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
1 parent 77885b8 commit 55e4d56

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

_includes/footer.htm

+20
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,24 @@
6565
},2000)
6666
}
6767

68+
69+
document.addEventListener('DOMContentLoaded', () => {
70+
const headers = document.querySelectorAll('h1[id], h2[id], h3[id], h4[id]');
71+
72+
headers.forEach(header => {
73+
const iconLink = document.createElement('a');
74+
iconLink.href = `#${header.id}`;
75+
iconLink.innerHTML = '#';
76+
iconLink.className = 'header-link';
77+
78+
// Wrap the icon inside a span to control visibility with CSS
79+
const wrapper = document.createElement('span');
80+
wrapper.className = 'header-link-wrapper';
81+
wrapper.appendChild(iconLink);
82+
83+
// Append the wrapper to the header
84+
header.appendChild(wrapper);
85+
});
86+
});
87+
6888
</script>

css/style.scss

+15
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,18 @@ div[class*="language-"] button{
108108
padding: 5px;
109109
}
110110

111+
.header-link-wrapper{
112+
visibility: hidden;
113+
margin-left: 2px;
114+
padding-left: 2px;
115+
}
116+
/* Show the icon link on hover */
117+
h1:hover .header-link-wrapper,
118+
h2:hover .header-link-wrapper,
119+
h3:hover .header-link-wrapper,
120+
h4:hover .header-link-wrapper {
121+
visibility: visible;
122+
}
123+
.header-link{
124+
color:#ccc !important
125+
}

0 commit comments

Comments
 (0)