From 77d3c8f66b0ab5c27c37240651eb17a188a0d52f Mon Sep 17 00:00:00 2001 From: dzfelix Date: Mon, 26 Aug 2024 23:29:30 +0400 Subject: [PATCH] main fix --- src/app/[locale]/(main)/@news/page.tsx | 77 ++++++++------------------ src/app/[locale]/blog/[slug]/page.tsx | 3 +- src/lib/contentful/blogPosts.ts | 10 +++- 3 files changed, 34 insertions(+), 56 deletions(-) diff --git a/src/app/[locale]/(main)/@news/page.tsx b/src/app/[locale]/(main)/@news/page.tsx index 2aa2a09..2dadcf5 100644 --- a/src/app/[locale]/(main)/@news/page.tsx +++ b/src/app/[locale]/(main)/@news/page.tsx @@ -1,71 +1,40 @@ import React from 'react'; import { useTranslations } from 'next-intl'; -import { unstable_setRequestLocale } from 'next-intl/server'; +import {getTranslations, unstable_setRequestLocale} from 'next-intl/server'; import { i18nText } from '../../../../i18nKeys'; +import {fetchBlogPosts} from "../../../../lib/contentful/blogPosts"; +import Link from "next/link"; -export default function News({ params: { locale } }: { params: { locale: string }}) { +export default async function News({params: {locale}}: { params: { locale: string } }) { unstable_setRequestLocale(locale); - const t = useTranslations('Main'); + const t = await getTranslations('Main'); + const {data, total} = await fetchBlogPosts({preview: false, sticky: true}) return (

{t('news')}

-
-
-
- -
-
-
News Headline
-
- The program not only focuses on a financial perspective, but allows you to study - performance from many angles, such as human resources management, IT, operations - management, risks etc. + {data.map((item, i) => ( +
+
+
+ {item.listImage?.alt}/ +
+
+
{item.title}
+
+ {item.excerpt} +
+ + {i18nText('readMore', locale)} + +
- {i18nText('readMore', locale)} - -
-
-
-
-
- -
-
-
News Headline
-
- The program not only focuses on a financial perspective, but allows you to study - performance from many angles, such as human resources management, IT, operations - management, risks etc. -
- {i18nText('readMore', locale)} - - -
-
-
-
-
-
- -
-
-
News Headline
-
- The program not only focuses on a financial perspective, but allows you to study - performance from many angles, such as human resources management, IT, operations - management, risks etc. -
- {i18nText('readMore', locale)} - - -
-
-
+ ))} +
diff --git a/src/app/[locale]/blog/[slug]/page.tsx b/src/app/[locale]/blog/[slug]/page.tsx index 2f6aefd..f344216 100644 --- a/src/app/[locale]/blog/[slug]/page.tsx +++ b/src/app/[locale]/blog/[slug]/page.tsx @@ -22,7 +22,8 @@ export async function generateMetadata({ params }: BlogPostPageProps, parent: Re } return { - title: blogPost.title + title: blogPost.title, + // description: blogPost.metaDescription } } diff --git a/src/lib/contentful/blogPosts.ts b/src/lib/contentful/blogPosts.ts index 415792c..92b75fd 100644 --- a/src/lib/contentful/blogPosts.ts +++ b/src/lib/contentful/blogPosts.ts @@ -68,8 +68,9 @@ interface FetchBlogPostsOptions { local?: string category?: string page?: number + sticky?: boolean } -export async function fetchBlogPosts({ preview, category, page }: FetchBlogPostsOptions): Promise<{ +export async function fetchBlogPosts({ preview, category, page, sticky }: FetchBlogPostsOptions): Promise<{ total: number; data: BlogPost[] }> { @@ -84,11 +85,18 @@ export async function fetchBlogPosts({ preview, category, page }: FetchBlogPosts query['fields.category.sys.contentType.sys.id']='blogPostCategory' } + if(page){ query['limit'] = pageSize query['skip'] = pageSize * (page - 1) } + if (sticky){ // только три для главной + query['fields.sticky'] = 1 + query['limit'] = 3 + query['skip'] = 0 + } + const blogPostsResult = await contentful.getEntries(query) const data = blogPostsResult.items.map((blogPostEntry) => parseContentfulBlogPost(blogPostEntry) as BlogPost)