Skip to content

Commit a87b433

Browse files
Feat: Add anchor links to blog post headings
This commit introduces anchor links to all headings in the blog posts. This allows users to directly link to specific sections of a post, improving navigation and shareability. The implementation uses a Hugo heading render hook to customize the HTML output of the headings. It also includes CSS to style the anchor links, making them visible only on hover to maintain a clean look.
1 parent 1ce6f9d commit a87b433

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

assets/scss/style.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,16 @@ body {
7272
line-height: 1.3;
7373
}
7474
}
75+
76+
.anchor-heading {
77+
position: relative;
78+
.anchor-link {
79+
position: absolute;
80+
left: -1em;
81+
opacity: 0;
82+
text-decoration: none;
83+
}
84+
&:hover .anchor-link {
85+
opacity: 1;
86+
}
87+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<h{{ .Level }} id="{{ .Anchor | safeURL }}" class="anchor-heading">
2+
<a href="#{{ .Anchor | safeURL }}" class="anchor-link">#</a>
3+
{{ .Text | safeHTML }}
4+
</h{{ .Level }}>

0 commit comments

Comments
 (0)