Skip to content

Commit d876abb

Browse files
committed
fix: sidebar expand
1 parent 5f12963 commit d876abb

12 files changed

Lines changed: 253 additions & 33 deletions

File tree

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"format": "prettier --write \"src/**/*.ts\" ",
2121
"lint": "eslint --fix",
2222
"preinstall": "sh scripts/preinstall.sh",
23-
"prepare": "simple-git-hooks"
23+
"prepare": "simple-git-hooks",
24+
"update:lastmodified": "tsx scripts/update-lastmodified.ts"
2425
},
2526
"dependencies": {
2627
"@afilmory/builder": "workspace:*",
@@ -51,7 +52,7 @@
5152
"vite-tsconfig-paths": "5.1.4"
5253
},
5354
"simple-git-hooks": {
54-
"pre-commit": "pnpm exec lint-staged"
55+
"pre-commit": "tsx scripts/update-lastmodified.ts && pnpm exec lint-staged"
5556
},
5657
"lint-staged": {
5758
"*.{js,jsx,ts,tsx}": [
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Docker
3+
description: Guide to deploying Afilmory via Docker.
4+
createdAt: 2025-07-20T22:35:03+08:00
5+
lastModified: 2025-08-08T08:28:42.778+08:00
6+
---
7+
8+
# Docker Deployment
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
---
22
title: Deployment
3-
description: Guide to deploying Afilmory Builder in production environments, including Docker and configuration options.
3+
description: Guide to deploying Afilmory in production environments, including Docker and configuration options.
44
createdAt: 2025-07-20T22:35:03+08:00
5-
lastModified: 2025-07-20T22:35:03+08:00
5+
lastModified: 2025-08-08T08:28:42.778+08:00
66
---
77

88
# Deployment
99

10-
Deploying Afilmory in production involves
10+
Deploying Afilmory can be accomplished through various methods, you can choose the one that best fits your needs. Below are the common deployment methods:
11+
12+
- [Docker Deployment](/deployment/docker)
13+
- [Github Action Deployment](/deployment/github-action)
14+
- [Github Pages Deployment](/deployment/github-pages)
15+
- [Vercel Deployment](/deployment/vercel)
16+
- [Cloudflare Pages Deployment](/deployment/cloudflare-pages)

packages/docs/scripts/build.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env node
22

3-
import { mkdir,readFile, writeFile } from 'node:fs/promises'
4-
import { dirname,join } from 'node:path'
5-
import { fileURLToPath, pathToFileURL } from 'node:url'
3+
import { mkdir, readFile, writeFile } from 'node:fs/promises'
4+
import { dirname, join } from 'node:path'
5+
import { fileURLToPath, pathToFileURL } from 'node:url'
66

7-
import type {RouteConfig} from '../src/routes';
7+
import type { RouteConfig } from '../src/routes'
88
import routes from '../src/routes.json'
99

1010
const __dirname = fileURLToPath(new URL('.', import.meta.url))
@@ -31,9 +31,9 @@ async function build() {
3131
.replace('<!--app-html-->', html)
3232
.replace(
3333
'<!--app-title-->',
34-
(route.meta?.title as string) ||
35-
route.title ||
36-
'Afilmory Documentation',
34+
`${
35+
(route.meta?.title as string) || route.title || 'Docs'
36+
} | Afilmory Docs`,
3737
)
3838
.replace('<!--app-head-->', generateMetaTags(route))
3939

@@ -64,7 +64,10 @@ function generateMetaTags(route: Omit<RouteConfig, 'component'>): string {
6464
const title = meta.title as string
6565

6666
if (description) {
67-
tags.push(`<meta name="description" content="${description}">`, `<meta property="og:description" content="${description}">`)
67+
tags.push(
68+
`<meta name="description" content="${description}">`,
69+
`<meta property="og:description" content="${description}">`,
70+
)
6871
}
6972

7073
if (title) {

packages/docs/src/App.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
import { AlignLeftIcon, ArrowRight } from 'lucide-react'
2-
import { useCallback, useRef, useState } from 'react'
2+
import { useCallback, useEffect, useRef, useState } from 'react'
33

44
import { MDX } from './components'
55
import { DocumentFooter } from './components/DocumentFooter'
66
import { MobileTableOfContents } from './components/MobileTableOfContents'
77
import { Sidebar } from './components/Sidebar'
88
import { TableOfContents } from './components/TableOfContents'
9-
import routes from './routes'
109
import { getRandomKaomoji } from './utils/kaomoji'
10+
import { getMatchedRoute } from './utils/routes'
1111

1212
function App({ url }: { url?: string }) {
1313
const [currentPath, setCurrentPath] = useState(url || '/')
1414
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)
2616
const mainContentRef = useRef<HTMLDivElement>(null)
2717

2818
const handleScrollMainContent = (top: number) => {
@@ -51,6 +41,14 @@ function App({ url }: { url?: string }) {
5141
setIsSidebarOpen(!isSidebarOpen)
5242
}, [isSidebarOpen])
5343

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+
5452
if (!matchedRoute) {
5553
return (
5654
<div className="bg-background flex h-screen">

packages/docs/src/components/DocumentFooter.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export function DocumentFooter({ createdAt, lastModified }: DocumentMetaProps) {
2424
return dateString
2525
}
2626
}
27-
console.info('Current theme:', theme)
2827
const themeOptions = [
2928
{ value: 'light', icon: Sun, label: 'Light' },
3029
{ value: 'system', icon: Monitor, label: 'System' },

packages/docs/src/components/Sidebar.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { ChevronRight } from 'lucide-react'
2-
import { useCallback, useState } from 'react'
2+
import { useCallback, useEffect, useState } from 'react'
33

44
import type { RouteConfig } from '../routes'
55
import { routes } from '../routes'
6+
import { getMatchedRoute } from '../utils/routes'
67

78
interface SidebarProps {
89
currentPath?: string
@@ -94,9 +95,16 @@ function NavigationItemComponent({
9495
}, [currentPath, item.path, item.children])
9596

9697
const [isExpanded, setIsExpanded] = useState(shouldExpand)
97-
const isActive = currentPath === item.path
98+
const isActive = currentPath
99+
? getMatchedRoute(currentPath)?.path === item.path
100+
: false
98101
const hasChildren = item.children && item.children.length > 0
99102

103+
// 当 currentPath 改变时,重新计算是否应该展开
104+
useEffect(() => {
105+
setIsExpanded(shouldExpand())
106+
}, [shouldExpand])
107+
100108
const handleTitleClick = () => {
101109
onNavigate?.(item.path)
102110
}

packages/docs/src/routes.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@
1313
"title": "Deployment",
1414
"meta": {
1515
"title": "Deployment",
16-
"description": "Guide to deploying Afilmory Builder in production environments, including Docker and configuration options.",
16+
"description": "Guide to deploying Afilmory in production environments, including Docker and configuration options.",
1717
"createdAt": "2025-07-20T22:35:03+08:00",
18-
"lastModified": "2025-07-20T22:35:03+08:00"
18+
"lastModified": "2025-08-08T08:28:42.778+08:00"
19+
}
20+
},
21+
{
22+
"path": "/deployment/docker",
23+
"title": "Docker",
24+
"meta": {
25+
"title": "Docker",
26+
"description": "Guide to deploying Afilmory via Docker.",
27+
"createdAt": "2025-07-20T22:35:03+08:00",
28+
"lastModified": "2025-08-08T08:28:42.778+08:00"
1929
}
2030
}
2131
]

packages/docs/src/routes.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// This file is automatically generated by the route-generator plugin
33
// Do not edit manually - your changes will be overwritten
44

5+
import Route2 from '../contents/deployment/docker.mdx'
56
import Route1 from '../contents/deployment/index.mdx'
67
import Route0 from '../contents/index.mdx'
78

@@ -30,9 +31,20 @@ export const routes: RouteConfig[] = [
3031
meta: {
3132
title: 'Deployment',
3233
description:
33-
'Guide to deploying Afilmory Builder in production environments, including Docker and configuration options.',
34+
'Guide to deploying Afilmory in production environments, including Docker and configuration options.',
3435
createdAt: '2025-07-20T22:35:03+08:00',
35-
lastModified: '2025-07-20T22:35:03+08:00',
36+
lastModified: '2025-08-08T08:28:42.778+08:00',
37+
},
38+
},
39+
{
40+
path: '/deployment/docker',
41+
component: Route2,
42+
title: 'Docker',
43+
meta: {
44+
title: 'Docker',
45+
description: 'Guide to deploying Afilmory via Docker.',
46+
createdAt: '2025-07-20T22:35:03+08:00',
47+
lastModified: '2025-08-08T08:28:42.778+08:00',
3648
},
3749
},
3850
]

packages/docs/src/toc-data.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,19 @@ export const tocData: FileToc[] = [
199199
},
200200
],
201201
},
202+
{
203+
file: 'deployment/docker.mdx',
204+
path: '/deployment/docker',
205+
title: 'Docker',
206+
toc: [
207+
{
208+
id: 'heading-docker-deployment',
209+
level: 1,
210+
text: 'Docker Deployment',
211+
children: [],
212+
},
213+
],
214+
},
202215
]
203216

204217
// Helper function to find TOC data by file path

0 commit comments

Comments
 (0)