2022-03-17 16:05:34 +00:00
|
|
|
import AppLayout from "components/AppLayout";
|
|
|
|
import Chip from "components/Chip";
|
|
|
|
import ThumbnailHeader from "components/Content/ThumbnailHeader";
|
|
|
|
import HorizontalLine from "components/HorizontalLine";
|
2022-03-20 12:21:30 +00:00
|
|
|
import LanguageSwitcher from "components/LanguageSwitcher";
|
2022-03-17 16:05:34 +00:00
|
|
|
import Markdawn from "components/Markdown/Markdawn";
|
|
|
|
import TOC from "components/Markdown/TOC";
|
|
|
|
import ReturnButton, {
|
|
|
|
ReturnButtonType,
|
|
|
|
} from "components/PanelComponents/ReturnButton";
|
|
|
|
import ContentPanel from "components/Panels/ContentPanel";
|
|
|
|
import SubPanel from "components/Panels/SubPanel";
|
|
|
|
import RecorderChip from "components/RecorderChip";
|
|
|
|
import ToolTip from "components/ToolTip";
|
2022-03-31 12:59:31 +00:00
|
|
|
import { GetPostQuery } from "graphql/generated";
|
|
|
|
import { getReadySdk } from "graphql/sdk";
|
2022-03-27 15:01:14 +00:00
|
|
|
import {
|
|
|
|
GetStaticPathsContext,
|
|
|
|
GetStaticPathsResult,
|
|
|
|
GetStaticPropsContext,
|
|
|
|
} from "next";
|
2022-03-17 16:05:34 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import { AppStaticProps, getAppStaticProps } from "queries/getAppStaticProps";
|
2022-03-28 08:43:25 +00:00
|
|
|
import {
|
|
|
|
getLocalesFromLanguages,
|
|
|
|
getStatusDescription,
|
|
|
|
prettySlug,
|
|
|
|
} from "queries/helpers";
|
2022-03-17 16:05:34 +00:00
|
|
|
|
2022-04-03 08:34:21 +00:00
|
|
|
interface Props extends AppStaticProps {
|
2022-03-31 12:59:31 +00:00
|
|
|
post: Exclude<
|
|
|
|
GetPostQuery["posts"],
|
|
|
|
null | undefined
|
|
|
|
>["data"][number]["attributes"];
|
|
|
|
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-03-28 08:43:25 +00:00
|
|
|
const { post, langui } = props;
|
2022-03-31 12:59:31 +00:00
|
|
|
const locales = getLocalesFromLanguages(post?.translations_languages);
|
2022-03-17 16:05:34 +00:00
|
|
|
const router = useRouter();
|
|
|
|
|
2022-03-31 12:59:31 +00:00
|
|
|
const thumbnail = post?.translations?.[0]?.thumbnail?.data
|
|
|
|
? post.translations[0].thumbnail.data.attributes
|
|
|
|
: post?.thumbnail?.data
|
|
|
|
? post.thumbnail.data.attributes
|
|
|
|
: undefined;
|
|
|
|
|
|
|
|
const body = post?.translations?.[0]?.body ?? "";
|
|
|
|
const title = post?.translations?.[0]?.title ?? prettySlug(post?.slug);
|
|
|
|
const except = post?.translations?.[0]?.excerpt ?? "";
|
2022-03-18 13:10:30 +00:00
|
|
|
|
2022-03-17 16:05:34 +00:00
|
|
|
const subPanel = (
|
|
|
|
<SubPanel>
|
|
|
|
<ReturnButton
|
|
|
|
href="/news"
|
|
|
|
title={langui.news}
|
|
|
|
langui={langui}
|
2022-03-27 15:01:14 +00:00
|
|
|
displayOn={ReturnButtonType.desktop}
|
2022-03-17 16:05:34 +00:00
|
|
|
horizontalLine
|
|
|
|
/>
|
|
|
|
|
2022-03-31 12:59:31 +00:00
|
|
|
{post?.translations?.[0] && (
|
2022-03-17 16:05:34 +00:00
|
|
|
<div className="grid grid-flow-col place-items-center place-content-center gap-2">
|
|
|
|
<p className="font-headers">{langui.status}:</p>
|
|
|
|
|
|
|
|
<ToolTip
|
|
|
|
content={getStatusDescription(post.translations[0].status, langui)}
|
|
|
|
maxWidth={"20rem"}
|
|
|
|
>
|
|
|
|
<Chip>{post.translations[0].status}</Chip>
|
|
|
|
</ToolTip>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
2022-03-31 12:59:31 +00:00
|
|
|
{post?.authors && post.authors.data.length > 0 && (
|
2022-03-17 16:05:34 +00:00
|
|
|
<div>
|
|
|
|
<p className="font-headers">{"Authors"}:</p>
|
|
|
|
<div className="grid place-items-center place-content-center gap-2">
|
|
|
|
{post.authors.data.map((author) => (
|
2022-03-31 12:59:31 +00:00
|
|
|
<>
|
|
|
|
{author.attributes && (
|
|
|
|
<RecorderChip
|
|
|
|
key={author.id}
|
|
|
|
langui={langui}
|
|
|
|
recorder={author.attributes}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
2022-03-17 16:05:34 +00:00
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<HorizontalLine />
|
|
|
|
|
2022-03-31 12:59:31 +00:00
|
|
|
<TOC text={body} title={title} />
|
2022-03-17 16:05:34 +00:00
|
|
|
</SubPanel>
|
|
|
|
);
|
|
|
|
const contentPanel = (
|
|
|
|
<ContentPanel>
|
|
|
|
<ReturnButton
|
|
|
|
href="/news"
|
|
|
|
title={langui.news}
|
|
|
|
langui={langui}
|
2022-03-27 15:01:14 +00:00
|
|
|
displayOn={ReturnButtonType.mobile}
|
2022-03-17 16:05:34 +00:00
|
|
|
className="mb-10"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<ThumbnailHeader
|
2022-03-18 13:10:30 +00:00
|
|
|
thumbnail={thumbnail}
|
2022-03-31 12:59:31 +00:00
|
|
|
title={title}
|
|
|
|
description={except}
|
2022-03-17 16:05:34 +00:00
|
|
|
langui={langui}
|
2022-03-31 12:59:31 +00:00
|
|
|
categories={post?.categories}
|
2022-03-17 16:05:34 +00:00
|
|
|
/>
|
|
|
|
|
|
|
|
<HorizontalLine />
|
|
|
|
|
2022-03-27 15:01:14 +00:00
|
|
|
{locales.includes(router.locale ?? "en") ? (
|
2022-03-31 12:59:31 +00:00
|
|
|
<Markdawn text={body} />
|
2022-03-20 12:21:30 +00:00
|
|
|
) : (
|
|
|
|
<LanguageSwitcher
|
|
|
|
locales={locales}
|
|
|
|
languages={props.languages}
|
|
|
|
langui={props.langui}
|
|
|
|
/>
|
2022-03-17 16:05:34 +00:00
|
|
|
)}
|
|
|
|
</ContentPanel>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<AppLayout
|
2022-03-31 12:59:31 +00:00
|
|
|
navTitle={title}
|
2022-03-17 16:05:34 +00:00
|
|
|
contentPanel={contentPanel}
|
|
|
|
subPanel={subPanel}
|
2022-03-31 12:59:31 +00:00
|
|
|
thumbnail={thumbnail ?? undefined}
|
2022-03-17 16:05:34 +00:00
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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",
|
|
|
|
});
|
|
|
|
if (!post.posts?.data[0]) 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
|
|
|
}
|