Skip to content

Commit 812ba29

Browse files
committed
Show anchor links on headings
1 parent 15c8841 commit 812ba29

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

input/Shared/_ChildPages.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
.ToDocumentList();
66
@if (!Document.GetBool(SiteKeys.NoChildPages) && children.Count > 0)
77
{
8-
<h4 class="h-section mb-2">Child Pages</h4>
8+
<h4 class="h-section mb-2 no-anchor">Child Pages</h4>
99
@foreach (IDocument child in children)
1010
{
1111
<div>

input/Shared/_ChildPagesItem.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@{
55
string excerpt = Model.GetString(Keys.Excerpt);
66
<div class="p-3 mb-2 bg-light page-box">
7-
<h4>@Html.DocumentLink(Model)</h4>
7+
<h4 class="no-anchor">@Html.DocumentLink(Model)</h4>
88

99
@if (!string.IsNullOrEmpty(excerpt))
1010
{

input/_Layout.cshtml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<script src="https://cdn.jsdelivr.net/npm/[email protected]/components/prism-core.min.js"></script>
3737
<script src="https://cdn.jsdelivr.net/npm/[email protected]/plugins/autoloader/prism-autoloader.min.js" data-no-mirror></script>
3838
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/quicklink.umd.js"></script>
39+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/anchor.min.js"></script>
3940

4041
<!-- Lunr search -->
4142
@if (Context.GetBool(WebKeys.GenerateSearchIndex))
@@ -233,6 +234,9 @@
233234

234235
<!-- Scripts -->
235236
<script>
237+
// Should run before document.ready. See https://github.com/bryanbraun/anchorjs/issues/69#issuecomment-255503575
238+
anchors.add('#content h1:not(.no-anchor), #content h2:not(.no-anchor), #content h3:not(.no-anchor), #content h4:not(.no-anchor)');
239+
236240
$(document).ready(function() {
237241
quicklink.listen();
238242

input/assets/css/theme.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,17 @@ code, code[class*="language-"], pre[class*="language-"] {
436436
}
437437
}
438438

439+
/* Anchors */
440+
441+
.anchorjs-link {
442+
color: $gray-400;
443+
444+
&:hover {
445+
color: $gray-400;
446+
text-decoration: none;
447+
}
448+
}
449+
439450
/* Mermaid */
440451
.mermaid {
441452
overflow: hidden !important;

0 commit comments

Comments
 (0)