Skip to content

Commit 6bcce0c

Browse files
committed
Make all headings in blog posts linkable
It's nice to be able to link certain sections of a blog post when trying to share ideas. Followed the steps [here](https://blog.briandrupieski.com/generate-anchors-in-jekyll-blog-post) to autogenerate links next to headers in posts jquery-3.4.1.min.js is from [here](https://code.jquery.com/jquery-3.4.1.min.js) anchor.min.js is from [here](https://github.com/bryanbraun/anchorjs/blob/4.2.0/anchor.min.js)
1 parent 8b7376b commit 6bcce0c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

_layouts/post.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
layout: default
33
---
44
<article id="post-page">
5+
<script src="/js/anchor.min.js"></script>
56
<h2>{{ page.title }}</h2>
67
<time datetime="{{ page.date | date_to_xmlschema }}" class="by-line">{{ page.date | date_to_string }}</time>
78
<div class="content">
@@ -29,5 +30,7 @@ <h2>{{ page.title }}</h2>
2930
d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
3031
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);
3132
})();
33+
anchors.options.visible = 'hover';
34+
anchors.add('.post-content > h1, h2, h3, h4, h5, h6');
3235
</script>
3336

js/anchor.min.js

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)