|
1 | 1 | 'use cache'; |
| 2 | +import { Metadata } from 'next'; |
2 | 3 | import { unstable_cacheLife as cacheLife, unstable_cacheTag as cacheTag } from 'next/cache'; |
3 | 4 | import { Suspense } from 'react'; |
4 | 5 |
|
5 | 6 | import { Header } from '@/components/header/header'; |
6 | 7 | import { Tab } from '@/components/tabs/tabs'; |
7 | 8 | import { TabsBar } from '@/components/tabs/tabs-bar'; |
| 9 | +import { fetchProfileData } from '@/graphql/helpers/fetch-profile-data'; |
8 | 10 | import { graphqlDirect } from '@/lib/graphql/graphql-direct'; |
9 | 11 | import { TopGlobalRankingsDocument } from '@/types/generated/graphql'; |
10 | 12 |
|
11 | 13 | import Loading from './loading'; |
12 | 14 |
|
13 | 15 | type ProfileLayoutProps = Readonly<{ children: React.ReactNode; params: Promise<{ login: string }> }>; |
14 | 16 |
|
| 17 | +export async function generateMetadata({ params }: { params: Promise<{ login: string }> }): Promise<Metadata> { |
| 18 | + const { login } = await params; |
| 19 | + const { user } = await fetchProfileData(login); |
| 20 | + |
| 21 | + if (!user) { |
| 22 | + return { title: 'GitHub Profile Analytics & Rankings · GitRanks' }; |
| 23 | + } |
| 24 | + |
| 25 | + const { s, c, f } = user.rankGlobal ?? {}; |
| 26 | + |
| 27 | + return { |
| 28 | + title: `${login} · GitHub Profile Analytics · GitRanks`, |
| 29 | + description: `Explore GitHub profile analytics for ${login} – ranked #${s} by stars, #${c} by contributions, and #${f} by followers.`, |
| 30 | + openGraph: { |
| 31 | + images: [user.avatarUrl!], |
| 32 | + }, |
| 33 | + }; |
| 34 | +} |
| 35 | + |
15 | 36 | export async function generateStaticParams() { |
16 | 37 | const { byStars, byContribution, byFollowers } = (await graphqlDirect(TopGlobalRankingsDocument)) ?? {}; |
17 | 38 | const mergedRanks = [...byStars, ...byContribution, ...byFollowers]; |
|
0 commit comments