Skip to content

Commit

Permalink
Add article heading anchors
Browse files Browse the repository at this point in the history
Adds heading anchors (#) that appear when user hovers over headings in
articles. Clicking the anchor will scroll viewport until heading is
aligned to top and update the address bar with the hash. This makes it
easy to copy URLs that link to a specific heading in the article.
  • Loading branch information
runofthemillgeek committed Nov 17, 2024
1 parent 4e760d1 commit 62972cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 14 additions & 1 deletion assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ h6 {
margin-bottom: var(--hx-margin-bottom);
}

.heading {
a {
text-decoration: none;
color: var(--content-secondary);
visibility: hidden;
font-size: 0.95em;
}

&:hover a {
visibility: visible;
}
}

p {
margin-top: var(--p-margin-top);
margin-bottom: var(--p-margin-bottom);
Expand Down Expand Up @@ -527,4 +540,4 @@ blockquote {
blockquote p {
margin-left: 1rem;
margin-right: 1rem;
}
}
4 changes: 4 additions & 0 deletions layouts/_default/_markup/render-heading.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h{{ .Level }} class="heading" id="{{ .Anchor }}">
{{ .Text }}
<a href="#{{ .Anchor }}">#</a>
</h{{ .Level }}>

0 comments on commit 62972cf

Please sign in to comment.