11import { Metadata } from 'next' ;
22import { notFound } from 'next/navigation' ;
3- import { models , findModelBySlug , getModelLicenses , isLegacyModel , Model } from '@/schema' ;
3+ import { permanentRedirect } from '@/i18n/navigation.server' ;
4+ import { models , findModelBySlug , findModelBySlugAlias , getModelLicenses , getModelSlugAliases , isLegacyModel , Model } from '@/schema' ;
45import { ThunderIcon , LampIcon , FlagIcon } from '@/components/icons/pixel' ;
56import { AVATAR_ICONS , getModelIconFallback } from '@/lib/icons' ;
67import { getModelColorFallback , MODEL_COLORS } from '@/lib/colors' ;
@@ -46,9 +47,10 @@ interface ModelPageProps {
4647
4748// Generate static params for all models
4849export async function generateStaticParams ( ) {
49- return models . map ( model => ( {
50- slug : model . slug ,
51- } ) ) ;
50+ return models . flatMap ( model => [
51+ model . slug ,
52+ ...getModelSlugAliases ( model ) ,
53+ ] . map ( slug => ( { slug } ) ) ) ;
5254}
5355
5456export const dynamicParams = true ;
@@ -59,7 +61,7 @@ export async function generateMetadata({
5961} : ModelPageProps ) : Promise < Metadata > {
6062 const { locale, slug } = ( await params ) as { locale : Locale ; slug : string } ;
6163 const l = await getLingo ( locale ) ;
62- const model = findModelBySlug ( slug ) ;
64+ const model = findModelBySlug ( slug ) ?? findModelBySlugAlias ( slug ) ;
6365
6466 if ( ! model ) {
6567 return {
@@ -143,12 +145,17 @@ const MAX_API_NAMES = 1;
143145export default async function ModelPage ( { params } : ModelPageProps ) {
144146 const { locale, slug } = ( await params ) as { locale : Locale ; slug : string } ;
145147 const l = await getLingo ( locale ) ;
146- const model = findModelBySlug ( slug ) ;
148+ const aliasModel = findModelBySlugAlias ( slug ) ;
149+ const model = aliasModel ?? findModelBySlug ( slug ) ;
147150
148151 if ( ! model ) {
149152 notFound ( ) ;
150153 }
151154
155+ if ( aliasModel ) {
156+ permanentRedirect ( `/models/${ aliasModel . slug } ` , locale ) ;
157+ }
158+
152159 const { description } = model . describe ( l ) ;
153160 const showRatings = ! model . hideRatings ;
154161 const speed = showRatings ? speedRating ( model . ratings . speed , l ) : null ;
0 commit comments