This commit is contained in:
2024-05-21 00:12:19 +02:00
parent 9e0466f78b
commit 963987278a
22 changed files with 1025 additions and 90 deletions

View File

@ -0,0 +1,68 @@
import { graphql } from "@/gql";
import { NewsFragment } from "@/gql/graphql";
import { getClient } from "@/app/client";
import { Blocks } from "@/components/blocks/Blocks";
import Image from "@/components/general/Image";
export async function generateStaticParams() {
const allNewsSlugsQuery = graphql(`
query allNewsSlugs {
pages(contentType: "news.NewsPage") {
id
slug
}
}
`);
const { data, error } = await getClient().query(allNewsSlugsQuery, {});
if (data === undefined || error) {
throw new Error("failed to generate static params");
}
return data?.pages.map((page: any) => ({
slug: page.slug,
}));
}
export default async function Page({ params }: { params: { slug: string } }) {
const newsBySlugQuery = graphql(`
query newsBySlug($slug: String!) {
news: page(contentType: "news.NewsPage", slug: $slug) {
... on NewsPage {
...News
}
}
}
`);
const { data, error } = await getClient().query(newsBySlugQuery, {
slug: params.slug,
});
const news = (data?.news ?? {}) as NewsFragment;
const featuredImage: any = news.featuredImage
console.log(data)
console.log('error', error)
return (
<main className="site-main" id="main">
<section className="page-header">
<h1>{news.title}</h1>
{featuredImage && (
<Image
src={featuredImage.url}
alt={featuredImage.alt}
width={featuredImage.width}
height={featuredImage.height}
sizes="100vw"
/>
)}
</section>
<section className="page-content">
<Blocks blocks={news.body} />
</section>
</main>
);
}