@@ -13,7 +13,7 @@ import { notFound } from "next/navigation"
1313
1414import { DocContent } from "@/app/(app)/docs/[[...slug]]/doc-content"
1515import { ComponentInstallation } from "@/components/component-installation"
16- import { ComponentPreviewInternal } from " @/components/component-preview-internal"
16+ import { ComponentPreview } from ' @/components/component-preview'
1717import { DocsTableOfContents } from "@/components/docs-toc"
1818import { LLMCopyButton } from '@/components/llm-copy-button'
1919import { mdxComponents } from "@/components/mdx-components"
@@ -45,6 +45,67 @@ export const dynamicParams = true
4545
4646const registryNames = new Set ( registry . items . map ( ( item ) => item . name ) )
4747
48+ // Helper function to filter page tree by locale
49+ function filterPageTreeByLocale ( pageTree : any , isChinese : boolean ) : any {
50+ if ( ! pageTree ) return pageTree
51+
52+ // Filter children array recursively
53+ const filterChildren = ( children : any [ ] ) : any [ ] => {
54+ if ( ! children ) return [ ]
55+
56+ return children
57+ . map ( ( node : any ) => {
58+ // Handle separator nodes
59+ if ( node . type === 'separator' ) {
60+ return node
61+ }
62+
63+ // Handle folder nodes
64+ if ( node . type === 'folder' ) {
65+ const filteredChildren = filterChildren ( node . children )
66+ // Only include folder if it has children after filtering
67+ if ( filteredChildren . length === 0 && ! node . index ) {
68+ return null
69+ }
70+
71+ // Check if folder index should be filtered
72+ if ( node . index ?. url ) {
73+ const isChineseNode = node . index . url . includes ( '.cn' )
74+ if ( isChinese !== isChineseNode ) {
75+ // Filter out the index but keep the folder if it has other valid children
76+ return {
77+ ...node ,
78+ children : filteredChildren ,
79+ index : undefined
80+ }
81+ }
82+ }
83+
84+ return {
85+ ...node ,
86+ children : filteredChildren
87+ }
88+ }
89+
90+ // Handle page nodes
91+ if ( node . url ) {
92+ const isChineseNode = node . url . includes ( '.cn' )
93+ if ( isChinese !== isChineseNode ) {
94+ return null
95+ }
96+ }
97+
98+ return node
99+ } )
100+ . filter ( Boolean ) // Remove null entries
101+ }
102+
103+ return {
104+ ...pageTree ,
105+ children : filterChildren ( pageTree . children )
106+ }
107+ }
108+
48109export function generateStaticParams ( ) {
49110 return docsSource . generateParams ( )
50111}
@@ -241,8 +302,9 @@ export default async function Page(props: DocPageProps) {
241302 usage = { file . meta ?. usage }
242303 />
243304 ) : (
244- < ComponentPreviewInternal
305+ < ComponentPreview
245306 name = { file . name }
307+ item = { item }
246308 />
247309 ) }
248310 </ DocContent >
@@ -251,7 +313,11 @@ export default async function Page(props: DocPageProps) {
251313
252314 const doc = page . data
253315 const MDX = doc . body
254- const neighbours = findNeighbour ( docsSource . pageTree , page . url )
316+
317+ // Filter neighbors to only include same language pages
318+ const isChinese = page . url . includes ( '.cn' )
319+ const filteredPageTree = filterPageTreeByLocale ( docsSource . pageTree , isChinese )
320+ const neighbours = findNeighbour ( filteredPageTree , page . url )
255321
256322 // Add description from docsMap if not present
257323 if ( ! doc . description ) {
@@ -282,7 +348,8 @@ export default async function Page(props: DocPageProps) {
282348 < h1 className = "scroll-m-20 text-4xl font-semibold tracking-tight sm:text-3xl xl:text-4xl" >
283349 { doc . title }
284350 </ h1 >
285- < div className = "flex items-center gap-2 pt-1.5" >
351+ { /* TODO: FIX */ }
352+ { /* <div className="flex items-center gap-2 pt-1.5">
286353 {neighbours.previous && (
287354 <Button
288355 asChild
@@ -309,7 +376,7 @@ export default async function Page(props: DocPageProps) {
309376 </Link>
310377 </Button>
311378 )}
312- </ div >
379+ </div> */ }
313380 </ div >
314381 { doc . description && (
315382 < p className = "text-muted-foreground text-[1.05rem] text-balance sm:text-base" >
0 commit comments