Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

docs: Don't render the table of contents on the print page #12340

Merged
merged 2 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/12340.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix rendering of the documentation site when using the 'print' feature.
14 changes: 14 additions & 0 deletions docs/website_files/table-of-contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ function setTocEntry() {
* Populate sidebar on load
*/
window.addEventListener('load', () => {
// Prevent rendering the table of contents of the "print book" page, as it
// will end up being rendered into the output (in a broken-looking way)

// Get the name of the current page (i.e. 'print.html')
const pageNameExtension = window.location.pathname.split('/').pop();

// Split off the extension (as '.../print' is also a valid page name), which
// should result in 'print'
const pageName = pageNameExtension.split('.')[0];
if (pageName === "print") {
// Don't render the table of contents on this page
return;
}

// Only create table of contents if there is more than one header on the page
if (headers.length <= 1) {
return;
Expand Down