Skip to content

Commit

Permalink
toc fix
Browse files Browse the repository at this point in the history
  • Loading branch information
trean committed Dec 5, 2024
1 parent 025cc21 commit 76bd937
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions qdrant-landing/content/articles/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ img: /articles_data/title-img.png
partition: learn
learnButton: Learn More
isMainPage: true
toc_start_level: 2
---
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ class TableOfContents {
constructor(tocSelector, contentSelector) {
this.tocLinks = Array.from(document.querySelectorAll(`${tocSelector} a`));
this.headings = Array.from(
document.querySelectorAll(
`${contentSelector} h1, ${contentSelector} h2, ${contentSelector} h3`,
),
document.querySelectorAll(`${contentSelector} h1[id], ${contentSelector} h2[id], ${contentSelector} h3[id]`),
);
this.currentActiveIndex = -1; // Track the current active heading index
this.currentActive = null; // Track the current active heading element


this.debounceTimeout = null;

this.currentlyVisibleHeaderIds = new Set();
Expand Down Expand Up @@ -46,7 +43,6 @@ class TableOfContents {
// Setup Intersection Observer
setupObserver() {
const observerCallback = (entries) => {

entries.forEach((entry) => {
const entryIndex = this.headings.indexOf(entry.target);
const isIntersecting = entry.isIntersecting;
Expand All @@ -57,7 +53,7 @@ class TableOfContents {
this.currentlyVisibleHeaderIds.delete(entryIndex);
}
});

if (this.currentlyVisibleHeaderIds.size !== 0) {
let minimalVisibleHeaderId = Math.min(...Array.from(this.currentlyVisibleHeaderIds));
this.setActiveLink(minimalVisibleHeaderId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
{{ if gt (.TableOfContents | len) 34 }}
<div class="table-of-contents">
<p class="table-of-contents__head">On this page:</p>

{{ .TableOfContents }}
{{ $tocStartLevel := .Params.toc_start_level }}
{{ if not $tocStartLevel }}
{{ $tocStartLevel = default 1 $.Parent.Params.toc_start_level }}
{{ end }}
{{ $tocEndLevel := default 3 .Params.toc_end_level }}
{{ $tocOrdered := false }}
{{ .Fragments.ToHTML $tocStartLevel $tocEndLevel $tocOrdered | safeHTML }}


<ul class="table-of-contents__external-links">
Expand Down

0 comments on commit 76bd937

Please sign in to comment.