Workaround TOC, Table of Contents for all Subpages of a Folder
closed
Adrian Pali
Currently we are using following JavaScript as a workaround:
<script type = "text/javascript" >
window.onload = function() {
let e = 'https://' + window.location.hostname + '/graphql?query={pages{search(query:"' + window.location.pathname.substring(window.location.pathname.lastIndexOf('/')) + '/"){results{path,title,description}}}}';
fetch(e)
.then(function(e) {
return e.json();
})
.then(function(e) {
let t = e.data.pages.search.results,
n = document.getElementById("toc");
t.sort(function(a, b) {
let titleA = a.title.toUpperCase();
let titleB = b.title.toUpperCase();
if (titleA < titleB) {
return -1;
}
if (titleA > titleB) {
return 1;
}
return 0;
});
n.innerHTML = "";
for (let e = 0; e < t.length; ++e) {
let i = document.createElement("li"),
a = document.createElement("a");
a.setAttribute("href", "/" + t[e].path), a.setAttribute("class", "is-internal-link is-valid-page"), (a.innerHTML = t[e].title + "<em>" + t[e].description), i.appendChild(a), n.appendChild(i);
}
});
};
</script>
add this to the script sections of a page and add following html to the page content while using the markdown or code editor:
<ul class="links-list" id="toc"></ul>
Mike Pl
Doesn't work for me, is this still working for you? The Preview stays blank.
It's running on Linux does it make a difference?
Nicolas Giard
closed
S
Stefan Drees
Is there a way to let this script only list pages being accessible to the user logged in?
I think about to only list subpages containing a special or multiple tags that mark groups...?
Nicolas Giard
Stefan Drees: Please continue this discussion on GitHub discussions. This site is not the place to ask questions / get support.
F
Fred Markle
I tried setting this up today, but no luck. Does this script still work? I created a html page and put the line of code into it. I also loaded the above javascript code into the scripts section for that page. It doesn't display any content on the page. We are running version 2.5.299.
S
Stefan Drees
Fred Markle: Enter the HTML code (short line) to the source code at the point you want the link list to appear ... (picture - yet i couldn't upload this) and paste the long JS code into the section found at: Page - Page Properties - Scripts