diff --git a/web/app/(commonLayout)/datasets/Container.tsx b/web/app/(commonLayout)/datasets/Container.tsx
index c39d9c5dbfd69b..f484d30a3d3f8d 100644
--- a/web/app/(commonLayout)/datasets/Container.tsx
+++ b/web/app/(commonLayout)/datasets/Container.tsx
@@ -82,7 +82,7 @@ const Container = () => {
}, [currentWorkspace, router])
return (
-
+
= ({
- apiBaseUrl,
-}) => {
+
+const Doc = ({ apiBaseUrl }: DocProps) => {
const { locale } = useContext(I18n)
+ const { t } = useTranslation()
+ const [toc, setToc] = useState>([])
+ const [isTocExpanded, setIsTocExpanded] = useState(false)
+ // Set initial TOC expanded state based on screen width
useEffect(() => {
- const hash = location.hash
- if (hash)
- document.querySelector(hash)?.scrollIntoView()
+ const mediaQuery = window.matchMedia('(min-width: 1280px)')
+ setIsTocExpanded(mediaQuery.matches)
}, [])
+ // Extract TOC from article content
+ useEffect(() => {
+ const extractTOC = () => {
+ const article = document.querySelector('article')
+ if (article) {
+ const headings = article.querySelectorAll('h2')
+ const tocItems = Array.from(headings).map((heading) => {
+ const anchor = heading.querySelector('a')
+ if (anchor) {
+ return {
+ href: anchor.getAttribute('href') || '',
+ text: anchor.textContent || '',
+ }
+ }
+ return null
+ }).filter((item): item is { href: string; text: string } => item !== null)
+ setToc(tocItems)
+ }
+ }
+
+ setTimeout(extractTOC, 0)
+ }, [locale])
+
+ // Handle TOC item click
+ const handleTocClick = (e: React.MouseEvent, item: { href: string; text: string }) => {
+ e.preventDefault()
+ const targetId = item.href.replace('#', '')
+ const element = document.getElementById(targetId)
+ if (element) {
+ const scrollContainer = document.querySelector('.scroll-container')
+ if (scrollContainer) {
+ const headerOffset = -40
+ const elementTop = element.offsetTop - headerOffset
+ scrollContainer.scrollTo({
+ top: elementTop,
+ behavior: 'smooth',
+ })
+ }
+ }
+ }
+
return (
-
- {
- locale !== LanguagesSupported[1]
+
+
+ {isTocExpanded
+ ? (
+
+ )
+ : (
+
+ )}
+
+
+ {locale !== LanguagesSupported[1]
?
:
- }
-
+ }
+
+
)
}