-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathpage.tsx
More file actions
46 lines (39 loc) · 1.38 KB
/
page.tsx
File metadata and controls
46 lines (39 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import dynamic from 'next/dynamic'
import type { Metadata } from 'next'
const WalkClient = dynamic(
() => import('../../../../src/components/Walk/WalkClient'),
{ ssr: true },
)
import getFilesystems from '../../../../src/lib/filesystems'
import type { Walk } from '../../../../src/types/pages'
export const metadata: Metadata = {
title: 'Admin > Walk - History App',
}
export const dynamicParams = false
export async function generateStaticParams() {
const allPaths = await getAllFolderPaths()
return allPaths.map(path => ({
path: path.split('/').filter(Boolean), // split into array, remove empty for catch-all segments
}))
}
async function getAllFolderPaths(path = '/') {
const { files } = await getFilesystems(path)
let paths: string[] = []
for (const file of files) {
if (file.mediumType === 'folder') {
const folderPath = path === '/' ? file.name : `${path}/${file.name}`
paths.push(folderPath)
// Recursively collect subfolders
const subPaths = await getAllFolderPaths(folderPath)
paths = paths.concat(subPaths)
}
}
return paths
}
export default async function Page({ params }: { params: Promise<Walk.Params> }) {
const { path: nextRoutePath = [] } = await params
const path = nextRoutePath.join('/')
const fsPath = path ? `/${path}` : '/'
const { files } = await getFilesystems(fsPath)
return <WalkClient files={files} />
}