2022-02-15 14:50:51 +00:00
|
|
|
import AppLayout from "components/AppLayout";
|
2022-03-20 12:21:30 +00:00
|
|
|
import LanguageSwitcher from "components/LanguageSwitcher";
|
2022-03-12 12:26:41 +00:00
|
|
|
import Markdawn from "components/Markdown/Markdawn";
|
2021-11-13 20:26:18 +00:00
|
|
|
import ContentPanel from "components/Panels/ContentPanel";
|
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 { GetStaticPropsContext } from "next";
|
2022-03-19 16:35:17 +00:00
|
|
|
import { useRouter } from "next/router";
|
2022-03-07 14:50:00 +00:00
|
|
|
import { AppStaticProps, getAppStaticProps } from "queries/getAppStaticProps";
|
2022-03-28 08:43:25 +00:00
|
|
|
import { getLocalesFromLanguages, prettySlug } from "queries/helpers";
|
2022-02-12 10:02:22 +00:00
|
|
|
|
2022-03-31 12:59:31 +00:00
|
|
|
interface Props extends AppStaticProps {
|
|
|
|
post: Exclude<
|
|
|
|
GetPostQuery["posts"],
|
|
|
|
null | undefined
|
|
|
|
>["data"][number]["attributes"];
|
2022-03-12 12:26:41 +00:00
|
|
|
}
|
2022-02-12 10:02:22 +00:00
|
|
|
|
2022-03-31 12:59:31 +00:00
|
|
|
export default function Home(props: Props): JSX.Element {
|
2022-03-28 08:43:25 +00:00
|
|
|
const { post } = props;
|
2022-03-31 12:59:31 +00:00
|
|
|
const locales = getLocalesFromLanguages(post?.translations_languages);
|
2022-03-19 16:35:17 +00:00
|
|
|
const router = useRouter();
|
|
|
|
|
2022-03-31 12:59:31 +00:00
|
|
|
const body = post?.translations?.[0]?.body ?? "";
|
|
|
|
const title = post?.translations?.[0]?.title ?? prettySlug(post?.slug);
|
|
|
|
|
2022-02-15 14:50:51 +00:00
|
|
|
const contentPanel = (
|
2022-03-12 12:26:41 +00:00
|
|
|
<ContentPanel>
|
2022-03-13 01:27:34 +00:00
|
|
|
<div className="grid place-items-center place-content-center w-full gap-5 text-center">
|
|
|
|
<div className="[mask:url('/icons/accords.svg')] [mask-size:contain] [mask-repeat:no-repeat] [mask-position:center] w-32 aspect-square mobile:w-[50vw] bg-black" />
|
|
|
|
<h1 className="text-5xl mb-0">Accord’s Library</h1>
|
2022-03-13 14:39:19 +00:00
|
|
|
<h2 className="text-xl -mt-5">
|
2022-04-04 09:08:54 +00:00
|
|
|
Discover • Analyze • Translate • Archive
|
2022-03-13 14:39:19 +00:00
|
|
|
</h2>
|
2022-03-13 01:27:34 +00:00
|
|
|
</div>
|
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-12 12:26:41 +00:00
|
|
|
)}
|
2022-02-15 14:50:51 +00:00
|
|
|
</ContentPanel>
|
|
|
|
);
|
2022-02-12 10:02:22 +00:00
|
|
|
|
2022-03-31 12:59:31 +00:00
|
|
|
return <AppLayout navTitle={title} contentPanel={contentPanel} {...props} />;
|
2022-01-01 02:31:55 +00:00
|
|
|
}
|
2022-02-12 10:02:22 +00:00
|
|
|
|
2022-03-27 15:01:14 +00:00
|
|
|
export async function getStaticProps(
|
|
|
|
context: GetStaticPropsContext
|
2022-03-31 12:59:31 +00:00
|
|
|
): Promise<{ notFound: boolean } | { props: Props }> {
|
|
|
|
const sdk = getReadySdk();
|
2022-03-20 12:21:30 +00:00
|
|
|
const slug = "home";
|
2022-03-31 12:59:31 +00:00
|
|
|
const post = await sdk.getPost({
|
|
|
|
slug: slug,
|
|
|
|
language_code: context.locale ?? "en",
|
|
|
|
});
|
|
|
|
if (!post.posts) return { notFound: true };
|
|
|
|
const props: Props = {
|
2022-03-07 14:50:00 +00:00
|
|
|
...(await getAppStaticProps(context)),
|
2022-03-31 12:59:31 +00:00
|
|
|
post: post.posts.data[0].attributes,
|
2022-03-07 14:50:00 +00:00
|
|
|
};
|
|
|
|
return {
|
|
|
|
props: props,
|
|
|
|
};
|
2022-03-27 15:01:14 +00:00
|
|
|
}
|