add the post title into the toc

This commit is contained in:
Xavier Valls Pla 2020-06-19 07:58:02 +02:00
parent c6433ee574
commit 432a6da204
1 changed files with 9 additions and 0 deletions

View File

@ -24,3 +24,12 @@ window.addEventListener('DOMContentLoaded', () => {
observer.observe(section);
});
});
// Post title doesn't get parsed as it is not part of the content file
(function addPostTitle2ToC() {
var toc = document.getElementById('TableOfContents');
if (!toc) return;
var title = document.getElementById("post__title").innerText;
var ul = toc.querySelector('ul');
ul.outerHTML = `<ul><li><a href="#post__title" class="active">${title}</a>${ul.outerHTML}</li></ul>`;
})();