@@ -10,23 +10,18 @@ import { FeatureIconContainer } from '@/components/dynamic-zone/features/feature
1010import { Heading } from '@/components/elements/heading' ;
1111import { Subheading } from '@/components/elements/subheading' ;
1212import { generateMetadataObject } from '@/lib/shared/metadata' ;
13- import fetchContentType from '@/lib/strapi/fetchContentType ' ;
14- import { Article } from '@/types/types' ;
13+ import { fetchCollectionType , fetchSingleType } from '@/lib/strapi' ;
14+ import type { Article } from '@/types/types' ;
1515
1616export async function generateMetadata ( props : {
1717 params : Promise < { locale : string } > ;
1818} ) : Promise < Metadata > {
1919 const params = await props . params ;
20- const pageData = await fetchContentType (
21- 'blog-page' ,
22- {
23- filters : { locale : params . locale } ,
24- populate : 'seo.metaImage' ,
25- } ,
26- true
27- ) ;
20+ const pageData = await fetchSingleType ( 'blog-page' , {
21+ locale : params . locale ,
22+ } ) ;
2823
29- const seo = pageData ? .seo ;
24+ const seo = pageData . seo ;
3025 const metadata = generateMetadataObject ( seo ) ;
3126 return metadata ;
3227}
@@ -35,22 +30,17 @@ export default async function Blog(props: {
3530 params : Promise < { locale : string ; slug : string } > ;
3631} ) {
3732 const params = await props . params ;
38- const blogPage = await fetchContentType (
39- 'blog-page' ,
40- {
41- filters : { locale : params . locale } ,
42- } ,
43- true
44- ) ;
45- const articles = await fetchContentType (
33+ const pageData = await fetchSingleType ( 'blog-page' , {
34+ locale : params . locale ,
35+ } ) ;
36+ const [ firstArticle , ...articles ] = await fetchCollectionType < Article [ ] > (
4637 'articles' ,
4738 {
48- filters : { locale : params . locale } ,
49- } ,
50- false
39+ filters : { locale : { $eq : params . locale } } ,
40+ }
5141 ) ;
5242
53- const localizedSlugs = blogPage . localizations ?. reduce (
43+ const localizedSlugs = pageData . localizations ?. reduce (
5444 ( acc : Record < string , string > , localization : any ) => {
5545 acc [ localization . locale ] = 'blog' ;
5646 return acc ;
@@ -68,22 +58,20 @@ export default async function Blog(props: {
6858 < IconClipboardText className = "h-6 w-6 text-white" />
6959 </ FeatureIconContainer >
7060 < Heading as = "h1" className = "mt-4" >
71- { blogPage . heading }
61+ { pageData . heading }
7262 </ Heading >
7363 < Subheading className = "max-w-3xl mx-auto" >
74- { blogPage . sub_heading }
64+ { pageData . sub_heading }
7565 </ Subheading >
7666 </ div >
7767
78- { articles . data . slice ( 0 , 1 ) . map ( ( article : Article ) => (
79- < BlogCard
80- article = { article }
81- locale = { params . locale }
82- key = { article . title }
83- />
84- ) ) }
68+ < BlogCard
69+ article = { firstArticle }
70+ locale = { params . locale }
71+ key = { firstArticle . title }
72+ />
8573
86- < BlogPostRows articles = { articles . data } />
74+ < BlogPostRows articles = { articles } />
8775 </ Container >
8876 </ div >
8977 ) ;
0 commit comments