Added fallback and avoid 404

This commit is contained in:
DrMint 2022-03-29 22:36:13 +02:00
parent 4dd1782389
commit 935c364a71
23 changed files with 74 additions and 32 deletions

View File

@ -26,7 +26,7 @@ export default function FourOhFour(props: FourOhFourProps): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: FourOhFourProps }> {
): Promise<{ notFound: boolean } | { props: FourOhFourProps }> {
const props: FourOhFourProps = {
...(await getAppStaticProps(context)),
};

36
src/pages/500.tsx Normal file
View File

@ -0,0 +1,36 @@
import AppLayout from "components/AppLayout";
import ReturnButton, {
ReturnButtonType,
} from "components/PanelComponents/ReturnButton";
import ContentPanel from "components/Panels/ContentPanel";
import { GetStaticPropsContext } from "next";
import { AppStaticProps, getAppStaticProps } from "queries/getAppStaticProps";
interface FiveHundredProps extends AppStaticProps {}
export default function FiveHundred(props: FiveHundredProps): JSX.Element {
const { langui } = props;
const contentPanel = (
<ContentPanel>
<h1>500 - Internal Server Error</h1>
<ReturnButton
href="/"
title="Home"
langui={langui}
displayOn={ReturnButtonType.both}
/>
</ContentPanel>
);
return <AppLayout navTitle="500" contentPanel={contentPanel} {...props} />;
}
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ notFound: boolean } | { props: FiveHundredProps }> {
const props: FiveHundredProps = {
...(await getAppStaticProps(context)),
};
return {
props: props,
};
}

View File

@ -80,7 +80,7 @@ export default function AccordsHandbook(
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: AccordsHandbookProps }> {
): Promise<{ notFound: boolean } | { props: AccordsHandbookProps }> {
const slug = "accords-handbook";
const props: AccordsHandbookProps = {
...(await getAppStaticProps(context)),

View File

@ -224,7 +224,7 @@ export default function AboutUs(props: ContactProps): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: ContactProps }> {
): Promise<{ notFound: boolean } | { props: ContactProps }> {
const slug = "contact";
const props: ContactProps = {
...(await getAppStaticProps(context)),

View File

@ -38,7 +38,7 @@ export default function AboutUs(props: AboutUsProps): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: AboutUsProps }> {
): Promise<{ notFound: boolean } | { props: AboutUsProps }> {
const props: AboutUsProps = {
...(await getAppStaticProps(context)),
};

View File

@ -78,7 +78,7 @@ export default function SiteInformation(props: SiteInfoProps): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: SiteInfoProps }> {
): Promise<{ notFound: boolean } | { props: SiteInfoProps }> {
const slug = "legality";
const props: SiteInfoProps = {
...(await getAppStaticProps(context)),

View File

@ -78,7 +78,7 @@ export default function SharingPolicy(props: SharingPolicyProps): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: SharingPolicyProps }> {
): Promise<{ notFound: boolean } | { props: SharingPolicyProps }> {
const slug = "sharing-policy";
const props: SharingPolicyProps = {
...(await getAppStaticProps(context)),

View File

@ -24,7 +24,7 @@ export default function Archives(props: ArchivesProps): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: ArchivesProps }> {
): Promise<{ notFound: boolean } | { props: ArchivesProps }> {
const props: ArchivesProps = {
...(await getAppStaticProps(context)),
};

View File

@ -22,9 +22,9 @@ export default function Chronicles(props: ChroniclesProps): JSX.Element {
);
}
export async function getStaticProps(context: GetStaticPropsContext): Promise<{
props: ChroniclesProps;
}> {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ notFound: boolean } | { props: ChroniclesProps }> {
const props: ChroniclesProps = {
...(await getAppStaticProps(context)),
};

View File

@ -134,17 +134,19 @@ export default function ContentIndex(props: ContentIndexProps): JSX.Element {
);
}
export async function getStaticProps(context: GetStaticPropsContext): Promise<{
props: ContentIndexProps;
}> {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ notFound: boolean } | { props: ContentIndexProps }> {
const content = (
await getContent({
slug: context.params?.slug?.toString() ?? "",
language_code: context.locale ?? "en",
})
).contents.data[0].attributes;
if (!content) return { notFound: true };
const props: ContentIndexProps = {
...(await getAppStaticProps(context)),
content: (
await getContent({
slug: context.params?.slug?.toString() ?? "",
language_code: context.locale ?? "en",
})
).contents.data[0].attributes,
content: content,
};
return {
props: props,

View File

@ -246,7 +246,7 @@ export default function ContentRead(props: ContentReadProps): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: ContentReadProps }> {
): Promise<{ notFound: boolean } | { props: ContentReadProps }> {
const slug = context.params?.slug?.toString() ?? "";
const content = (
await getContentText({
@ -254,6 +254,7 @@ export async function getStaticProps(
language_code: context.locale ?? "en",
})
).contents.data[0];
if (!content) return { notFound: true };
const props: ContentReadProps = {
...(await getAppStaticProps(context)),
content: content.attributes,

View File

@ -101,7 +101,7 @@ export default function Contents(props: ContentsProps): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: ContentsProps }> {
): Promise<{ notFound: boolean } | { props: ContentsProps }> {
const contents = (
await getContents({
language_code: context.locale ?? "en",

View File

@ -91,7 +91,7 @@ export default function Editor(props: EditorProps): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: EditorProps }> {
): Promise<{ notFound: boolean } | { props: EditorProps }> {
const props: EditorProps = {
...(await getAppStaticProps(context)),
};

View File

@ -24,7 +24,7 @@ export default function Gallery(props: GalleryProps): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: GalleryProps }> {
): Promise<{ notFound: boolean } | { props: GalleryProps }> {
const props: GalleryProps = {
...(await getAppStaticProps(context)),
};

View File

@ -54,7 +54,7 @@ export default function Home(props: HomeProps): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: HomeProps }> {
): Promise<{ notFound: boolean } | { props: HomeProps }> {
const slug = "home";
const props: HomeProps = {
...(await getAppStaticProps(context)),

View File

@ -416,13 +416,14 @@ export default function LibrarySlug(props: LibrarySlugProps): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: LibrarySlugProps }> {
): Promise<{ notFound: boolean } | { props: LibrarySlugProps }> {
const item = (
await getLibraryItem({
slug: context.params?.slug?.toString() ?? "",
language_code: context.locale ?? "en",
})
).libraryItems.data[0];
if (!item) return { notFound: true };
const props: LibrarySlugProps = {
...(await getAppStaticProps(context)),
item: item.attributes,

View File

@ -146,13 +146,14 @@ export default function LibrarySlug(props: Props): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: Props }> {
): Promise<{ notFound: boolean } | { props: Props }> {
const item = (
await getLibraryItemScans({
slug: context.params?.slug?.toString() ?? "",
language_code: context.locale ?? "en",
})
).libraryItems.data[0];
if (!item) return { notFound: true };
const props: Props = {
...(await getAppStaticProps(context)),
item: item.attributes,

View File

@ -167,7 +167,7 @@ export default function Library(props: LibraryProps): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: LibraryProps }> {
): Promise<{ notFound: boolean } | { props: LibraryProps }> {
const props: LibraryProps = {
...(await getAppStaticProps(context)),
items: (

View File

@ -22,7 +22,7 @@ export default function Merch(props: MerchProps): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: MerchProps }> {
): Promise<{ notFound: boolean } | { props: MerchProps }> {
const props: MerchProps = {
...(await getAppStaticProps(context)),
};

View File

@ -146,7 +146,7 @@ export default function LibrarySlug(props: PostProps): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: PostProps }> {
): Promise<{ notFound: boolean } | { props: PostProps }> {
const slug = context.params?.slug?.toString() ?? "";
const post = (
await getPost({
@ -154,6 +154,7 @@ export async function getStaticProps(
language_code: context.locale ?? "en",
})
).posts.data[0];
if (!post) return { notFound: true };
const props: PostProps = {
...(await getAppStaticProps(context)),
post: post.attributes,

View File

@ -60,7 +60,7 @@ export default function News(props: NewsProps): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: NewsProps }> {
): Promise<{ notFound: boolean } | { props: NewsProps }> {
const props: NewsProps = {
...(await getAppStaticProps(context)),
posts: await (

View File

@ -143,7 +143,7 @@ export default function Chronology(props: ChronologyProps): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: ChronologyProps }> {
): Promise<{ notFound: boolean } | { props: ChronologyProps }> {
const props: ChronologyProps = {
...(await getAppStaticProps(context)),
chronologyItems: (

View File

@ -25,7 +25,7 @@ export default function Wiki(props: WikiProps): JSX.Element {
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<{ props: WikiProps }> {
): Promise<{ notFound: boolean } | { props: WikiProps }> {
const props: WikiProps = {
...(await getAppStaticProps(context)),
};