Fix making header linkable
This commit is contained in:
parent
ef7d0fe108
commit
0d7267f52a
2 changed files with 9 additions and 6 deletions
|
@ -28,7 +28,7 @@
|
||||||
<h1>{{ .Page.Title }}</h1>
|
<h1>{{ .Page.Title }}</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="post-content">
|
<div class="post-content" id="post-content">
|
||||||
{{ .Page.Content }}
|
{{ .Page.Content }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -25,11 +25,14 @@ var isMobile = false, isTablet = false, isLaptop = false;
|
||||||
element.innerHTML = `<a href="#${element.id}" class="header-anchor">${element.innerHTML}<sup><i class="fas fa-link"></i></sup></a>`;
|
element.innerHTML = `<a href="#${element.id}" class="header-anchor">${element.innerHTML}<sup><i class="fas fa-link"></i></sup></a>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
var headerTypes = ["h1", "h2", "h3", "h4", "h5", "h6"];
|
var postContent = document.getElementById("post-content");
|
||||||
for (var i = 0; i < headerTypes.length; i++) {
|
if (postContent != null) {
|
||||||
var headers = document.querySelectorAll(headerTypes[i]);
|
var headerTypes = ["h1", "h2", "h3", "h4", "h5", "h6"];
|
||||||
if (headers) {
|
for (var i = 0; i < headerTypes.length; i++) {
|
||||||
headers.forEach(addAnchor);
|
var headers = postContent.querySelectorAll(headerTypes[i]);
|
||||||
|
if (headers) {
|
||||||
|
headers.forEach(addAnchor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue