Add and initialize toc.js

This commit is contained in:
Philipp Oppermann
2016-07-17 16:21:53 +02:00
parent a8534a7bd7
commit 4000c990f0
2 changed files with 28 additions and 0 deletions

View File

@@ -30,6 +30,7 @@
<!-- JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/2.0.0/anchor.min.js"></script>
<script src="js/toc.min.js"></script>
{{ partial "analytics.html" . }}
<!-- redirect from phil-opp.github.io/blog_os -->
@@ -37,5 +38,23 @@
if (window.location.hostname == "phil-opp.github.io") {
window.location.href = "http://os.phil-opp.com/";
}
window.onload = function() {
var container = document.querySelector('#toc');
var selector = "h2";
if (container.className.split(" ").indexOf("coarse") == -1) {
selector += ",h3";
}
var toc = initTOC({
selector: selector,
scope: '.post',
overwrite: false,
prefix: 'toc'
});
container.appendChild(toc);
}
</script>
</head>