nextjs-tailwindcss-headless.../app/components/page.tsx

36 lines
854 B
TypeScript
Raw Normal View History

2023-08-25 21:53:07 +08:00
import Link from "next/link";
import fs from 'fs';
import path from 'path';
export async function getData() {
let dirs: string[] = [];
try {
fs.readdirSync(__dirname).filter(item => {
const p = path.resolve(__dirname, item);
const stat = fs.statSync(p);
if (stat.isDirectory()) dirs.push(item)
});
} catch (e) {
console.error(e)
}
return dirs;
}
export default async function Page() {
const list = await getData();
return (
<>
<span>Components List</span>
{
list.map(i => {
return (
<li key={i}>
<Link href={`/components/${i}`}>{i}</Link>
</li>
)
})
}
</>
)
}