accords-library.com/src/pages/news/[slug].tsx

59 lines
1.6 KiB
TypeScript
Raw Normal View History

import { PostPage } from "components/PostPage";
2022-05-08 19:37:41 +00:00
import { AppStaticProps } from "graphql/getAppStaticProps";
import {
getPostStaticProps,
PostStaticProps,
} from "graphql/getPostStaticProps";
import { getReadySdk } from "graphql/sdk";
2022-05-08 19:37:41 +00:00
import { Immutable } from "helpers/types";
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-05-08 19:37:41 +00:00
export default function LibrarySlug(props: Immutable<Props>): JSX.Element {
const { post, langui, languages, currencies } = props;
2022-03-17 16:05:34 +00:00
return (
2022-05-07 09:19:28 +00:00
<PostPage
currencies={currencies}
languages={languages}
langui={langui}
post={post}
returnHref="/news"
returnTitle={langui.news}
displayCredits
displayThumbnailHeader
displayToc
2022-03-17 16:05:34 +00:00
/>
);
}
export async function getStaticProps(
context: GetStaticPropsContext
2022-04-03 08:34:21 +00:00
): Promise<{ notFound: boolean } | { props: Props }> {
const slug = context.params?.slug ? context.params.slug.toString() : "";
2022-05-08 19:37:41 +00:00
return await getPostStaticProps(slug)(context);
}
2022-03-17 16:05:34 +00:00
export async function getStaticPaths(
context: GetStaticPathsContext
): Promise<GetStaticPathsResult> {
const sdk = getReadySdk();
const posts = await sdk.getPostsSlugs();
const paths: GetStaticPathsResult["paths"] = [];
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,
fallback: "blocking",
2022-03-17 16:05:34 +00:00
};
}