Added script to make list of headers

Added a new script with the purpose of getting all headers from a post's content and creating links for them in the left sidebar.
Some div classes have been modified, and a wrapper div has been added to posts because of this new script.
Some minor CSS changes have been made.
This commit is contained in:
Lorenzo Dellacà
2020-11-05 16:14:13 +01:00
parent 84f9eadd3b
commit 83302f7cc3
7 changed files with 93 additions and 43 deletions

View File

@@ -0,0 +1,16 @@
$(document).ready(function () {
const headers = $(".mind-post_content h2, .mind-post_content h3").toArray();
const sidebar = $("#mind-post_sidebar-left");
for (let i = 0; i < headers.length; i++) {
const currentHeader = headers[i];
const headerText = $(currentHeader).text();
const headerId = $(currentHeader).attr("id");
const headerType = $(currentHeader).prop("nodeName").toLowerCase();
// <h2> <a href="header-linke"> Header Name </a> </h2>
const newLine = "<" + headerType + "> <a href=\"#" + headerId + "\">" + headerText + "</a> </" + headerType + ">";
sidebar.append(newLine);
}
});