add news
This commit is contained in:
68
web/src/app/aktuelt/[slug]/page.tsx
Normal file
68
web/src/app/aktuelt/[slug]/page.tsx
Normal 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>
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user