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:
16
assets/js/get-headers-list.js
Normal file
16
assets/js/get-headers-list.js
Normal 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);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user