1+ import { Metadata } from 'next' ;
12import { client } from '../../../../tina/__generated__/databaseClient' ;
23import { getRefConfig } from '../../../../referentiel-config' ;
34import { PersonasPage } from '../../../../components/pages/personas-page' ;
45import { getStaticPathsFromFilesystem } from '../../../../utils/get-static-paths' ;
56import { notFound } from 'next/navigation' ;
7+ import { ui } from '../../../../i18n/ui' ;
8+ import { useTranslations } from '../../../../i18n/utils' ;
69
710export function generateStaticParams ( ) {
811 if ( ! getRefConfig ( ) . featuresEnabled . linkToPersonas ) {
@@ -11,6 +14,50 @@ export function generateStaticParams() {
1114 return getStaticPathsFromFilesystem ( 'personas' ) ;
1215}
1316
17+ export async function generateMetadata ( {
18+ params,
19+ } : {
20+ params : { lang : keyof typeof ui ; slug : string } ;
21+ } ) : Promise < Metadata > {
22+ const { lang, slug } = params ;
23+ const t = useTranslations ( lang ) ;
24+
25+ try {
26+ const res = await client . queries . personas ( {
27+ relativePath : `${ lang } /${ slug } .mdx` ,
28+ } ) ;
29+
30+ const persona = res . data . personas ;
31+ const title = `${ persona . title } | ${ t ( 'seo.site_name' ) } ` ;
32+ const description = persona . title ;
33+
34+ return {
35+ title,
36+ description,
37+ openGraph : {
38+ title,
39+ description,
40+ url : `${ t ( 'seo.url' ) } /${ lang } /personas/${ slug } ` ,
41+ siteName : t ( 'seo.site_name' ) ,
42+ images : [ { url : t ( 'seo.fb.image.url' ) , alt : persona . title } ] ,
43+ locale : lang ,
44+ type : 'article' ,
45+ } ,
46+ twitter : {
47+ card : 'summary_large_image' ,
48+ title,
49+ description,
50+ images : [ t ( 'seo.tw.image.url' ) ] ,
51+ } ,
52+ } ;
53+ } catch {
54+ return {
55+ title : t ( 'seo.site_name' ) ,
56+ description : t ( 'seo.default.description' ) ,
57+ } ;
58+ }
59+ }
60+
1461export default async function Page ( { params } ) {
1562 if ( ! getRefConfig ( ) . featuresEnabled . linkToPersonas ) {
1663 notFound ( ) ;
0 commit comments