import { getTranslations, setRequestLocale } from 'next-intl/server'; import { Header } from '@/components/Header'; import { Footer } from '@/components/Footer'; import { createDb, skillQueries } from '@skillhub/db'; import { toPersianNumber } from '@/lib/format-number'; import { Pagination } from '@/components/BrowseFilters'; import { SkillCard } from '@/components/SkillCard'; import { getPageAlternates } from '@/lib/seo'; // Force dynamic rendering to fetch fresh data from database export const dynamic = 'force-dynamic'; interface FeaturedPageProps { params: Promise<{ locale: string }>; searchParams: Promise<{ page?: string }>; } // Get featured skills with pagination async function getFeaturedSkills(page: number, limit: number) { try { const db = createDb(); const offset = (page - 1) * limit; // Try featured first, fall back to combined popularity score let featuredSkills = await skillQueries.getFeatured(db, limit, offset); let total = await skillQueries.countFeatured(db); // If no featured skills, use adaptive popularity with owner/repo diversity if (total === 0) { featuredSkills = await skillQueries.getFeaturedWithDiversity(db, limit, 2, 3); total = await skillQueries.countAll(db); } return { skills: featuredSkills, total }; } catch (error) { console.error('Error fetching featured skills:', error); return { skills: [], total: 0 }; } } export async function generateMetadata({ params, }: { params: Promise<{ locale: string }>; }) { const { locale } = await params; return { alternates: getPageAlternates(locale, '/featured'), }; } export default async function FeaturedPage({ params, searchParams, }: FeaturedPageProps) { const { locale } = await params; const searchParamsResolved = await searchParams; setRequestLocale(locale); const t = await getTranslations('featured'); const tBrowse = await getTranslations('browse'); const limit = 12; const page = parseInt(searchParamsResolved.page || '1'); const { skills: featuredSkills, total } = await getFeaturedSkills(page, limit); const totalPages = Math.ceil(total / limit); const startItem = (page - 1) * limit + 1; const endItem = Math.min(page * limit, total); const paginationTranslations = { previous: tBrowse('pagination.previous'), next: tBrowse('pagination.next'), page: tBrowse('pagination.page'), of: tBrowse('pagination.of'), }; return (

{t('title')}

{t('subtitle')}

{/* Results count */} {total > 0 && (

{tBrowse('resultsRange', { start: locale === 'fa' ? toPersianNumber(startItem) : startItem, end: locale === 'fa' ? toPersianNumber(endItem) : endItem, total: locale === 'fa' ? toPersianNumber(total) : total })}

)}
{featuredSkills.map((skill) => ( ))}
{/* Pagination */}
); }