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

60 lines
2.3 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-06-18 19:53:23 +00:00
import { filterHasAttributes, isDefined } from "helpers/others";
import { GetStaticPaths, GetStaticPathsResult, GetStaticProps } from "next";
2022-06-18 02:39:18 +00:00
/*
*
* PAGE
*/
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
const LibrarySlug = (props: Props): JSX.Element => (
<PostPage
returnHref="/news"
returnTitle={props.langui.news}
displayCredits
displayThumbnailHeader
displayToc
{...props}
/>
);
export default LibrarySlug;
/*
*
* NEXT DATA FETCHING
*/
export const getStaticProps: GetStaticProps = async (context) => {
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-17 16:05:34 +00:00
export const getStaticPaths: GetStaticPaths = async (context) => {
const sdk = getReadySdk();
const posts = await sdk.getPostsSlugs();
const paths: GetStaticPathsResult["paths"] = [];
2022-06-18 19:53:23 +00:00
filterHasAttributes(posts.posts?.data).map((item) => {
context.locales?.map((local) =>
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
};
};