mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Move ToC initialization code into own js file
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
<!-- JS -->
|
<!-- JS -->
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/2.0.0/anchor.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/2.0.0/anchor.min.js"></script>
|
||||||
<script src="js/toc.min.js"></script>
|
<script src="js/toc.min.js"></script>
|
||||||
|
<script src="js/main.js"></script>
|
||||||
{{ partial "analytics.html" . }}
|
{{ partial "analytics.html" . }}
|
||||||
|
|
||||||
<!-- redirect from phil-opp.github.io/blog_os -->
|
<!-- redirect from phil-opp.github.io/blog_os -->
|
||||||
@@ -38,28 +39,5 @@
|
|||||||
if (window.location.hostname == "phil-opp.github.io") {
|
if (window.location.hostname == "phil-opp.github.io") {
|
||||||
window.location.href = "http://os.phil-opp.com/";
|
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'
|
|
||||||
});
|
|
||||||
|
|
||||||
var heading = document.createElement("H2");
|
|
||||||
var heading_text = document.createTextNode("Table of Contents");
|
|
||||||
heading.appendChild(heading_text);
|
|
||||||
|
|
||||||
container.appendChild(heading);
|
|
||||||
container.appendChild(toc);
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
22
static/js/main.js
Normal file
22
static/js/main.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
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'
|
||||||
|
});
|
||||||
|
|
||||||
|
var heading = document.createElement("H2");
|
||||||
|
var heading_text = document.createTextNode("Table of Contents");
|
||||||
|
heading.appendChild(heading_text);
|
||||||
|
|
||||||
|
container.appendChild(heading);
|
||||||
|
container.appendChild(toc);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user