Adding anchors to my posts

1. Download the javascripts required to enable anchors

Download the latest release from this Git repo. Just copy the anchor.min.js file into public/css/ path. Then download the jQuery script from their official website. Download the compressed production version. Copy this script to public/css/ path as well.

2. Adding the scipt to post.html

Just add the following codeblock at the start of _layouts/post.html and you are done.

---
layout: default
---

<script src="/public/css/anchor.min.js"></script>
<script src="/public/css/jquery-3.5.1.min.js"></script>
<script>
	$(function() {
    anchors.options.visible = 'always'; 
    anchors.add('.post-content > h1, h2, h3, h4, h5, h6');
	});
</script>

References

  1. Blog on generating anchors
Originally published on: 14 Jul 2020