2022-05-14 12:45:29 +00:00
|
|
|
import { PostPage } from "components/PostPage";
|
2022-05-08 19:37:41 +00:00
|
|
|
import { AppStaticProps } from "graphql/getAppStaticProps";
|
|
|
|
import {
|
|
|
|
getPostStaticProps,
|
|
|
|
PostStaticProps,
|
|
|
|
} from "graphql/getPostStaticProps";
|
2022-03-31 12:59:31 +00:00
|
|
|
import { getReadySdk } from "graphql/sdk";
|
2022-06-18 02:02:20 +00:00
|
|
|
import { isDefined } from "helpers/others";
|
2022-06-18 02:39:18 +00:00
|
|
|
|
2022-03-27 15:01:14 +00:00
|
|
|
import {
|
|
|
|
GetStaticPathsContext,
|
|
|
|
GetStaticPathsResult,
|
|
|
|
GetStaticPropsContext,
|
|
|
|
} from "next";
|
2022-03-17 16:05:34 +00:00
|
|
|
|
2022-05-08 19:37:41 +00:00
|
|
|
interface Props extends AppStaticProps, PostStaticProps {}
|
2022-03-17 16:05:34 +00:00
|
|
|
|
2022-06-18 02:39:18 +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-06-18 02:02:20 +00:00
|
|
|
const slug =
|
|
|
|
context.params && isDefined(context.params.slug)
|
|
|
|
? context.params.slug.toString()
|
|
|
|
: "";
|
2022-05-08 19:37:41 +00:00
|
|
|
return await getPostStaticProps(slug)(context);
|
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
|
|
|
}
|