2022-05-08 10:21:29 +00:00
|
|
|
import PostPage from "components/PostPage";
|
2022-03-31 12:59:31 +00:00
|
|
|
import { GetPostQuery } from "graphql/generated";
|
|
|
|
import { getReadySdk } from "graphql/sdk";
|
2022-05-08 10:21:29 +00:00
|
|
|
import { AppStaticProps, getAppStaticProps } from "helpers/getAppStaticProps";
|
|
|
|
import { Post } from "helpers/types";
|
2022-03-27 15:01:14 +00:00
|
|
|
import {
|
|
|
|
GetStaticPathsContext,
|
|
|
|
GetStaticPathsResult,
|
|
|
|
GetStaticPropsContext,
|
|
|
|
} from "next";
|
2022-03-17 16:05:34 +00:00
|
|
|
|
2022-04-03 08:34:21 +00:00
|
|
|
interface Props extends AppStaticProps {
|
2022-05-07 09:19:28 +00:00
|
|
|
post: Post;
|
2022-03-31 12:59:31 +00:00
|
|
|
postId: Exclude<
|
|
|
|
GetPostQuery["posts"],
|
|
|
|
null | undefined
|
|
|
|
>["data"][number]["id"];
|
2022-03-17 16:05:34 +00:00
|
|
|
}
|
|
|
|
|
2022-04-03 08:34:21 +00:00
|
|
|
export default function LibrarySlug(props: Props): JSX.Element {
|
2022-04-12 10:25:40 +00:00
|
|
|
const { post, langui, languages, currencies } = props;
|
2022-03-17 16:05:34 +00:00
|
|
|
return (
|
2022-05-07 09:19:28 +00:00
|
|
|
<PostPage
|
2022-04-12 10:25:40 +00:00
|
|
|
currencies={currencies}
|
|
|
|
languages={languages}
|
|
|
|
langui={langui}
|
|
|
|
post={post}
|
|
|
|
returnHref="/news"
|
|
|
|
returnTitle={langui.news}
|
|
|
|
displayCredits
|
|
|
|
displayThumbnailHeader
|
|
|
|
displayToc
|
2022-03-17 16:05:34 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-03-27 15:01:14 +00:00
|
|
|
export async function getStaticProps(
|
|
|
|
context: GetStaticPropsContext
|
2022-04-03 08:34:21 +00:00
|
|
|
): Promise<{ notFound: boolean } | { props: Props }> {
|
2022-03-31 12:59:31 +00:00
|
|
|
const sdk = getReadySdk();
|
|
|
|
const slug = context.params?.slug ? context.params.slug.toString() : "";
|
|
|
|
const post = await sdk.getPost({
|
|
|
|
slug: slug,
|
|
|
|
language_code: context.locale ?? "en",
|
|
|
|
});
|
2022-05-07 09:17:58 +00:00
|
|
|
if (!post.posts?.data[0].attributes) return { notFound: true };
|
2022-04-03 08:34:21 +00:00
|
|
|
const props: Props = {
|
2022-03-17 16:05:34 +00:00
|
|
|
...(await getAppStaticProps(context)),
|
2022-03-31 12:59:31 +00:00
|
|
|
post: post.posts.data[0].attributes,
|
|
|
|
postId: post.posts.data[0].id,
|
2022-03-17 16:05:34 +00:00
|
|
|
};
|
|
|
|
return {
|
|
|
|
props: props,
|
|
|
|
};
|
2022-03-27 15:01:14 +00:00
|
|
|
}
|
2022-03-17 16:05:34 +00:00
|
|
|
|
2022-03-27 15:01:14 +00:00
|
|
|
export async function getStaticPaths(
|
|
|
|
context: GetStaticPathsContext
|
|
|
|
): Promise<GetStaticPathsResult> {
|
2022-03-31 12:59:31 +00:00
|
|
|
const sdk = getReadySdk();
|
|
|
|
const posts = await sdk.getPostsSlugs();
|
2022-03-27 15:01:14 +00:00
|
|
|
const paths: GetStaticPathsResult["paths"] = [];
|
2022-03-31 12:59:31 +00:00
|
|
|
if (posts.posts)
|
|
|
|
posts.posts.data.map((item) => {
|
|
|
|
context.locales?.map((local) => {
|
|
|
|
if (item.attributes)
|
|
|
|
paths.push({ params: { slug: item.attributes.slug }, locale: local });
|
|
|
|
});
|
2022-03-17 16:05:34 +00:00
|
|
|
});
|
|
|
|
return {
|
|
|
|
paths,
|
2022-03-29 19:51:50 +00:00
|
|
|
fallback: "blocking",
|
2022-03-17 16:05:34 +00:00
|
|
|
};
|
2022-03-27 15:01:14 +00:00
|
|
|
}
|