Skip to content

Commit

Permalink
FIX: max heading level set to 3/2 for toc (#323)
Browse files Browse the repository at this point in the history
* fix; max heading level set to 2 for toc

* fix: fixed toc for pages where heading was greater than 2
  • Loading branch information
viralgupta authored Aug 10, 2024
1 parent 30e68ba commit 73656d1
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 15 deletions.
1 change: 1 addition & 0 deletions docs/api/app.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Neutralino.app
toc_max_heading_level: 2
---

`Neutralino.app` namespace contains methods related to the current application instance.
Expand Down
1 change: 1 addition & 0 deletions docs/api/clipboard.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Neutralino.clipboard
toc_max_heading_level: 2
---

`Neutralino.clipboard` namespace offers functions to access system clipboard.
Expand Down
1 change: 1 addition & 0 deletions docs/api/computer.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Neutralino.computer
toc_max_heading_level: 2
---

`Neutralino.computer` namespace contains methods related to the user's hardware.
Expand Down
1 change: 1 addition & 0 deletions docs/api/custom.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Neutralino.custom
toc_max_heading_level: 2
---

Neutralinojs offers the extensions API to write custom backend code with any programming language,
Expand Down
1 change: 1 addition & 0 deletions docs/api/debug.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Neutralino.debug
toc_max_heading_level: 2
---

`Neutralino.debug` namespace contains application debugging utilities.
Expand Down
1 change: 1 addition & 0 deletions docs/api/error-codes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Error Codes
toc_max_heading_level: 2
---

If a particular native API call fails, Neutralinojs client library rejects the pending Promise with an error object.
Expand Down
1 change: 1 addition & 0 deletions docs/api/events.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Neutralino.events
toc_max_heading_level: 2
---

`Neutralino.events` namespace contains methods related to the native events handling. These events are often initiated
Expand Down
1 change: 1 addition & 0 deletions docs/api/extensions.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Neutralino.extensions
toc_max_heading_level: 2
---

`Neutralino.extensions` namespace contains methods related to Neutralino extensions. Extensions let
Expand Down
1 change: 1 addition & 0 deletions docs/api/filesystem.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Neutralino.filesystem
toc_max_heading_level: 2
---

`Neutralino.filesystem` namespace contains methods for handling files.
Expand Down
1 change: 1 addition & 0 deletions docs/api/global-variables.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Global Variables
toc_max_heading_level: 2
---

These JavaScript variables can be used anywhere because these variables are defined in the window scope.
Expand Down
1 change: 1 addition & 0 deletions docs/api/init.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Neutralino.init
toc_max_heading_level: 2
---

`init` is not a namespace, it's a function that initializes a Neutralinojs application.
Expand Down
1 change: 1 addition & 0 deletions docs/api/os.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Neutralino.os
toc_max_heading_level: 2
---

`Neutralino.os` namespace contains methods related to the user's operating system.
Expand Down
1 change: 1 addition & 0 deletions docs/api/overview.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Native API Overview
toc_max_heading_level: 2
---

Neutralinojs offers a JavaScript client library (also known as Neutralino.js) for developers to interact
Expand Down
1 change: 1 addition & 0 deletions docs/api/storage.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Neutralino.storage
toc_max_heading_level: 2
---

Neutralinojs has a built-in shared key-value storage. It's like a
Expand Down
1 change: 1 addition & 0 deletions docs/api/updater.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Neutralino.updater
toc_max_heading_level: 2
---

`Neutralino.updater` namespace contains methods related to built-in automatic updater. Neutralinojs offers
Expand Down
1 change: 1 addition & 0 deletions docs/api/window.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Neutralino.window
toc_max_heading_level: 2
---

The `Neutralino.window` namespace contains methods related to the current native window instance.
Expand Down
36 changes: 21 additions & 15 deletions src/theme/DocItem/TOC/Desktop/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import { useTOCHighlight } from "@docusaurus/theme-common/internal"
const LINK_CLASS_NAME = 'table-of-contents__link';
const ACTIVE_LINK_CLASS_NAME = 'table-of-contents__link--active';
const TOP_OFFSET = 100;
const MAX_HEADING_LEVEL = 3;

/* eslint-disable jsx-a11y/control-has-associated-label */
function Headings({
toc,
isChild,
frontMatter
}) {
if (!toc) {
return null;
Expand All @@ -21,23 +23,27 @@ function Headings({
className={
isChild ? '' : 'table-of-contents table-of-contents__left-border'
}>
{toc.map((heading) => (
<li key={heading.id}>
<a
href={`#${heading.id}`}
className={LINK_CLASS_NAME}
// Developer provided the HTML, so assume it's safe.
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{ __html: heading.value }}
/>
<Headings isChild toc={heading.children} />
</li>
))}
{toc.map((heading) => {
const LOCAL_MAX_HEADING_VALUE = frontMatter.toc_max_heading_level ? frontMatter.toc_max_heading_level : MAX_HEADING_LEVEL
if(heading.level > LOCAL_MAX_HEADING_VALUE) return null
return (
<li key={heading.id}>
<a
href={`#${heading.id}`}
className={LINK_CLASS_NAME}
// Developer provided the HTML, so assume it's safe.
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{ __html: heading.value }}
/>
<Headings isChild toc={heading.children} />
</li>
)
})}
</ul>
);
}

function CustomTOC({ toc }) {
function CustomTOC({ toc, frontMatter }) {
useTOCHighlight({linkClassName: LINK_CLASS_NAME, linkActiveClassName: ACTIVE_LINK_CLASS_NAME, maxHeadingLevel: TOP_OFFSET, minHeadingLevel: 0});
const [isInitialized, setIsInitialized] = useState(false);
const [isEthABlocked, setIsEthABlocked] = useState(false)
Expand All @@ -63,14 +69,14 @@ function CustomTOC({ toc }) {
>
</div>
</div>
<Headings toc={toc} />
<Headings toc={toc} frontMatter={frontMatter}/>
</div>
);
}

export default function DocItemTOCDesktop() {
const {toc, frontMatter} = useDoc();
return (
<CustomTOC toc={toc}/>
<CustomTOC toc={toc} frontMatter={frontMatter}/>
);
}

0 comments on commit 73656d1

Please sign in to comment.