Skip to content

Commit be50775

Browse files
Fix TOC hierarchy on floating nav (#556)
1 parent 1cd9350 commit be50775

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

components/utilities/floatingNav.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ const useHeadingsData = (slug) => {
1313
)
1414
);
1515

16+
// Remove the first heading here, since we don't want to show the main title on the TOC
17+
headingElements.shift();
18+
1619
const newNestedHeadings = getNestedHeadings(headingElements);
1720
setNestedHeadings(newNestedHeadings);
1821
}, [slug]);
@@ -25,6 +28,7 @@ const getNestedHeadings = (headingElements) => {
2528

2629
for (const index in headingElements) {
2730
const ele = headingElements[index];
31+
2832
if (ele.getElementsByTagName === undefined) {
2933
continue;
3034
}
@@ -128,6 +132,7 @@ const Headings = ({ headings, activeId }) => {
128132
// For example, we could have [H1, H2, H3] but also [H1, H4],
129133
// and we want the indentation to acommodate for these situations.
130134
const uniqueHierarchies = [...new Set(headings.map((item) => item.level))];
135+
131136
const sortedHeadings = uniqueHierarchies.map((hierarchy, index) =>
132137
headings.filter((heading) => {
133138
if (heading.level === hierarchy) {

components/utilities/floatingNav.module.css

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
}
44

55
.List {
6-
@apply sticky top-24 m-0 list-none overflow-y-auto overflow-x-hidden;
6+
@apply sticky top-24 m-0 pl-6 list-none overflow-y-auto overflow-x-hidden;
77
max-height: calc(100vh - (6em * 2));
88
}
99

@@ -21,15 +21,10 @@
2121

2222
/* Contents Title */
2323
.ListTitle {
24-
@apply pt-6 pl-6 uppercase font-semibold tracking-widest;
24+
@apply pt-6 uppercase font-semibold tracking-widest;
2525
@apply text-gray-60 !important;
2626
}
2727

28-
/* Hide the first h1 on the page, as it's the page title */
29-
.List li:nth-child(2) {
30-
@apply hidden;
31-
}
32-
3328
/* Styles for the active item on the floating nav */
3429
:global(.dark) .activeLink {
3530
@apply text-white !important;
@@ -45,6 +40,10 @@
4540
}
4641

4742
/* Paddings for different title hierarchies */
43+
.List li[data-hierarchy="0"] {
44+
@apply pl-0;
45+
}
46+
4847
.List li[data-hierarchy="1"] {
4948
@apply pl-6;
5049
}

0 commit comments

Comments
 (0)