|
| 1 | +import ReleaseCard from '@/components/release'; |
| 2 | +import { projects } from '@/projects.config'; |
| 3 | +import { fetchReleases } from '@/scripts/generate-releases'; |
| 4 | +import { Release } from '@/types'; |
| 5 | +import fs from 'fs'; |
| 6 | +import Link from 'next/link'; |
| 7 | +import { notFound } from 'next/navigation'; |
| 8 | +import path from 'path'; |
| 9 | + |
| 10 | +// 生成静态路径参数 |
| 11 | +export async function generateStaticParams() { |
| 12 | + await fetchReleases() |
| 13 | + return projects.map(project => ({ |
| 14 | + project: project.repo, |
| 15 | + })); |
| 16 | +} |
| 17 | + |
| 18 | +interface ProjectPageProps { |
| 19 | + params: { |
| 20 | + project: string; |
| 21 | + }; |
| 22 | +} |
| 23 | + |
| 24 | +export default async function ProjectPage({ params }: ProjectPageProps) { |
| 25 | + const { project: repo } = await params; |
| 26 | + |
| 27 | + // 查找项目信息 |
| 28 | + const project = projects.find(p => p.repo === repo); |
| 29 | + |
| 30 | + if (!project) { |
| 31 | + notFound(); |
| 32 | + } |
| 33 | + |
| 34 | + // 读取存储的 releases 数据 |
| 35 | + let releases: Release[] = []; |
| 36 | + try { |
| 37 | + releases = JSON.parse( |
| 38 | + fs.readFileSync(path.join(process.cwd(), 'data', repo, 'releases.json'), 'utf8') |
| 39 | + ); |
| 40 | + } catch (error) { |
| 41 | + console.error('Failed to load releases data:', error); |
| 42 | + } |
| 43 | + |
| 44 | + return ( |
| 45 | + <div className="container mx-auto px-4 py-8"> |
| 46 | + <div className="mb-6"> |
| 47 | + <Link href="/" className="text-blue-600 hover:underline flex items-center gap-1"> |
| 48 | + ← Back to all projects |
| 49 | + </Link> |
| 50 | + </div> |
| 51 | + |
| 52 | + <h1 className="text-3xl font-bold mb-2">{project.title || project.repo}</h1> |
| 53 | + {project.description && <p className="text-gray-600 mb-8">{project.description}</p>} |
| 54 | + |
| 55 | + {releases.length > 0 ? ( |
| 56 | + <div className="space-y-6"> |
| 57 | + {releases.map(release => ( |
| 58 | + <ReleaseCard key={release.id} project={project} release={release} /> |
| 59 | + ))} |
| 60 | + </div> |
| 61 | + ) : ( |
| 62 | + <p>No releases found for this project.</p> |
| 63 | + )} |
| 64 | + </div> |
| 65 | + ); |
| 66 | +} |
0 commit comments