FIX: Restore support for docs plugin (#24)

This commit is contained in:
Penar Musaraj 2022-01-19 12:50:45 -05:00 committed by GitHub
parent ff434a4f7b
commit 0bc2aa28a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 41 deletions

View File

@ -212,3 +212,10 @@ a.d-toc-close {
content: "#{$composer_toc_text}";
}
}
// Docs plugin outlet
.below-docs-topic-outlet.d-toc-wrapper {
position: sticky;
top: calc(var(--header-offset, 60px) + 1em);
max-height: calc(100vh - 2em - var(--header-offset, 60px));
}

View File

@ -0,0 +1 @@
{{!-- Docs TOC placeholder --}}

View File

@ -76,11 +76,26 @@ export default {
}
});
api.onAppEvent("docs-topic:current-post-scrolled", () => {
this.updateTOCSidebar();
});
api.onAppEvent("topic:current-post-scrolled", (args) => {
if (args.postIndex !== 1) {
return;
}
this.updateTOCSidebar();
});
api.cleanupStream(() => {
document.body.classList.remove("d-toc-timeline-visible");
document.removeEventListener("click", this.clickTOC, false);
});
});
},
updateTOCSidebar() {
if (!document.querySelector(".d-toc-cooked")) {
return;
}
@ -93,10 +108,7 @@ export default {
const distance = Math.abs(
domUtils.offset(heading).top - headerOffset() - window.scrollY
);
if (
closestHeadingDistance == null ||
distance < closestHeadingDistance
) {
if (closestHeadingDistance == null || distance < closestHeadingDistance) {
closestHeadingDistance = distance;
closestHeading = heading;
} else {
@ -122,13 +134,6 @@ export default {
liParent.classList.add("active");
});
}
});
api.cleanupStream(() => {
document.body.classList.remove("d-toc-timeline-visible");
document.removeEventListener("click", this.clickTOC, false);
});
});
},
insertTOC(headings) {