|
1 | 1 | import { AlignLeftIcon, ArrowRight } from 'lucide-react' |
2 | | -import { useCallback, useRef, useState } from 'react' |
| 2 | +import { useCallback, useEffect, useRef, useState } from 'react' |
3 | 3 |
|
4 | 4 | import { MDX } from './components' |
5 | 5 | import { DocumentFooter } from './components/DocumentFooter' |
6 | 6 | import { MobileTableOfContents } from './components/MobileTableOfContents' |
7 | 7 | import { Sidebar } from './components/Sidebar' |
8 | 8 | import { TableOfContents } from './components/TableOfContents' |
9 | | -import routes from './routes' |
10 | 9 | import { getRandomKaomoji } from './utils/kaomoji' |
| 10 | +import { getMatchedRoute } from './utils/routes' |
11 | 11 |
|
12 | 12 | function App({ url }: { url?: string }) { |
13 | 13 | const [currentPath, setCurrentPath] = useState(url || '/') |
14 | 14 | const [isSidebarOpen, setIsSidebarOpen] = useState(false) |
15 | | - const matchedRoute = routes.find((route) => { |
16 | | - const normalizedCurrentPath = |
17 | | - currentPath.endsWith('/') && currentPath !== '/' |
18 | | - ? currentPath.slice(0, -1) |
19 | | - : currentPath |
20 | | - const normalizedRoutePath = |
21 | | - route.path.endsWith('/') && route.path !== '/' |
22 | | - ? route.path.slice(0, -1) |
23 | | - : route.path |
24 | | - return normalizedRoutePath === normalizedCurrentPath |
25 | | - }) |
| 15 | + const matchedRoute = getMatchedRoute(currentPath) |
26 | 16 | const mainContentRef = useRef<HTMLDivElement>(null) |
27 | 17 |
|
28 | 18 | const handleScrollMainContent = (top: number) => { |
@@ -51,6 +41,14 @@ function App({ url }: { url?: string }) { |
51 | 41 | setIsSidebarOpen(!isSidebarOpen) |
52 | 42 | }, [isSidebarOpen]) |
53 | 43 |
|
| 44 | + useEffect(() => { |
| 45 | + if (matchedRoute) { |
| 46 | + document.title = `${matchedRoute.title || 'Docs'} | Afilmory Docs` |
| 47 | + } else { |
| 48 | + document.title = '404 Page Not Found | Afilmory Docs' |
| 49 | + } |
| 50 | + }, [matchedRoute]) |
| 51 | + |
54 | 52 | if (!matchedRoute) { |
55 | 53 | return ( |
56 | 54 | <div className="bg-background flex h-screen"> |
|
0 commit comments