Skip to content

Commit 0a9b5b6

Browse files
authored
Add custom TOC component with ad image (#569)
1 parent 6d58680 commit 0a9b5b6

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/images/pro-ad.png

23.7 KB
Loading

src/theme/TOC/index.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React, {type ReactNode} from 'react';
2+
import clsx from 'clsx';
3+
import TOCItems from '@theme/TOCItems';
4+
import type {Props} from '@theme/TOC';
5+
6+
import styles from './styles.module.css';
7+
8+
// Using a custom className
9+
// This prevents TOCInline/TOCCollapsible getting highlighted by mistake
10+
const LINK_CLASS_NAME = 'table-of-contents__link toc-highlight';
11+
const LINK_ACTIVE_CLASS_NAME = 'table-of-contents__link--active';
12+
import proAd from '../../images/pro-ad.png';
13+
14+
export default function TOC({className, ...props}: Props): ReactNode {
15+
return (
16+
<div className={clsx(styles.tableOfContents, 'thin-scrollbar', className)}>
17+
<TOCItems
18+
{...props}
19+
linkClassName={LINK_CLASS_NAME}
20+
linkActiveClassName={LINK_ACTIVE_CLASS_NAME}
21+
/>
22+
<div style={{
23+
marginTop: '12px',
24+
}}>
25+
<a href='https://www.lxware.cn/halo-shop?code=mcYhwMkn'>
26+
<img src={proAd} />
27+
</a>
28+
</div>
29+
</div>
30+
);
31+
}

src/theme/TOC/styles.module.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.tableOfContents {
2+
max-height: calc(100vh - (var(--ifm-navbar-height) + 2rem));
3+
overflow-y: auto;
4+
position: sticky;
5+
top: calc(var(--ifm-navbar-height) + 1rem);
6+
}
7+
8+
@media (max-width: 996px) {
9+
.tableOfContents {
10+
display: none;
11+
}
12+
13+
.docItemContainer {
14+
padding: 0 0.3rem;
15+
}
16+
}

0 commit comments

Comments
 (0)