Skip to content

Commit d8b16cb

Browse files
committed
make it more generic
1 parent 4dc7e14 commit d8b16cb

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

docs/platforms/javascript/common/options.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ sidebar_order: 2
99

1010
## Available Options
1111

12-
<SdkOptionsOverview />
12+
<TableOfContents ignoreIds={['available-options']} />
1313

1414
## Core Options
1515

src/components/docPage/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Mermaid from '../mermaid';
1919
import {PaginationNav} from '../paginationNav';
2020
import {PlatformSdkDetail} from '../platformSdkDetail';
2121
import {Sidebar} from '../sidebar';
22-
import {TableOfContents} from '../tableOfContents';
22+
import {SidebarTableOfContents} from '../sidebarTableOfContents';
2323
import {ReaderDepthTracker} from '../track-reader-depth';
2424

2525
type Props = {
@@ -110,7 +110,7 @@ export function DocPage({
110110
{hasToc && (
111111
<aside className="sticky h-[calc(100vh-var(--header-height))] top-[var(--header-height)] overflow-y-auto hidden xl:block w-[250px]">
112112
<div className="sidebar">
113-
<TableOfContents />
113+
<SidebarTableOfContents />
114114
<PlatformSdkDetail />
115115
</div>
116116
</aside>

src/components/tableOfContents/index.tsx renamed to src/components/sidebarTableOfContents/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function buildTocTree(toc: TocItem[]): TocItem[] {
7878
// https://github.com/vercel/next.js/discussions/57631
7979
//
8080
// For now, calculate the table of contents on the client.
81-
export function TableOfContents() {
81+
export function SidebarTableOfContents() {
8282
const [tocItems, setTocItems] = useState<TocItem[]>([]);
8383

8484
// gather the toc items on mount

src/components/sdkOptionOverview.tsx renamed to src/components/tableOfContents.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ type TreeNode = {
1515
name: string;
1616
};
1717

18-
export function SdkOptionsOverview() {
18+
interface Props {
19+
ignoreIds?: string[];
20+
}
21+
22+
export function TableOfContents({ignoreIds = []}: Props) {
1923
const [treeItems, setTreeItems] = useState<TreeItem[]>([]);
2024

2125
// gather the sdk option items on mount
@@ -25,13 +29,13 @@ export function SdkOptionsOverview() {
2529
}
2630
const main = document.getElementById('main');
2731
if (!main) {
28-
throw new Error('#main element not found');
32+
return;
2933
}
3034
const nodes = Array.from(main.querySelectorAll('h2, h3'))
3135
.map(el => {
3236
const name = el.textContent?.trim() ?? '';
3337
const id = el.id;
34-
if (!id || !name) {
38+
if (!id || !name || ignoreIds.includes(id)) {
3539
return null;
3640
}
3741
return {
@@ -56,7 +60,7 @@ export function SdkOptionsOverview() {
5660
children: [],
5761
};
5862
_tocItems.push(currentItem);
59-
} else if (node.element.hasAttribute('data-sdk-option')) {
63+
} else {
6064
currentItem.children.push({
6165
id: node.id,
6266
name: node.name,
@@ -67,7 +71,7 @@ export function SdkOptionsOverview() {
6771

6872
// Remove groups without children
6973
setTreeItems(_tocItems.filter(item => item.children.length > 0));
70-
}, []);
74+
}, [ignoreIds]);
7175

7276
return (
7377
<ul>

src/mdxComponents.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ import {PlatformSection} from './components/platformSection';
3232
import {RelayMetrics} from './components/relayMetrics';
3333
import {SandboxLink} from './components/sandboxLink';
3434
import {SdkOption} from './components/sdkOption';
35-
import {SdkOptionsOverview} from './components/sdkOptionOverview';
3635
import {SignInNote} from './components/signInNote';
3736
import {SmartLink} from './components/smartLink';
37+
import {TableOfContents} from './components/tableOfContents';
3838
import {VimeoEmbed} from './components/video';
3939

4040
export function mdxComponents(
@@ -52,7 +52,7 @@ export function mdxComponents(
5252
CodeTabs,
5353
ConfigKey,
5454
SdkOption,
55-
SdkOptionsOverview,
55+
TableOfContents,
5656
CreateGitHubAppForm,
5757
ConfigValue,
5858
DefinitionList,

0 commit comments

Comments
 (0)