Skip to content

Commit

Permalink
Fix making header linkable
Browse files Browse the repository at this point in the history
  • Loading branch information
hossainemruz committed Jun 21, 2020
1 parent ef7d0fe commit 0d7267f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h5 class="author-name">{{ partial "helpers/get-author-name.html" . }}</h5>
<h1>{{ .Page.Title }}</h1>
</div>

<div class="post-content">
<div class="post-content" id="post-content">
{{ .Page.Content }}
</div>

Expand Down
13 changes: 8 additions & 5 deletions static/assets/js/single.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>`;
}

var headerTypes = ["h1", "h2", "h3", "h4", "h5", "h6"];
for (var i = 0; i < headerTypes.length; i++) {
var headers = document.querySelectorAll(headerTypes[i]);
if (headers) {
headers.forEach(addAnchor);
var postContent = document.getElementById("post-content");
if (postContent != null) {
var headerTypes = ["h1", "h2", "h3", "h4", "h5", "h6"];
for (var i = 0; i < headerTypes.length; i++) {
var headers = postContent.querySelectorAll(headerTypes[i]);
if (headers) {
headers.forEach(addAnchor);
}
}
}

Expand Down

0 comments on commit 0d7267f

Please sign in to comment.