Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduced not found / error layout #6247

Merged
merged 11 commits into from
Jan 17, 2024
32 changes: 23 additions & 9 deletions app/[locale]/not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
'use client';

import { useTranslations } from 'next-intl';
import { getLocale } from 'next-intl/server';
import type { FC } from 'react';

const LocalizedNotFound: FC = () => {
const t = useTranslations();
import { MDXRenderer } from '@/components/mdxRenderer';
import WithLayout from '@/components/withLayout';
import { ENABLE_WEBSITE_REDESIGN } from '@/next.constants.mjs';
import { dynamicRouter } from '@/next.dynamic.mjs';

const LocalizedNotFound: FC = async () => {
const locale = await getLocale();

/** @deprecated replace the legacy page when website redesign is done */
const notFoundSource = ENABLE_WEBSITE_REDESIGN ? 'new-design/404' : '404';

canerakdas marked this conversation as resolved.
Show resolved Hide resolved
// Retrieves the markdown source created for the not-found page
const { source, filename } = await dynamicRouter.getMarkdownFile(
locale,
notFoundSource
);

// Parses the source Markdown content and returns a React Component
const { MDXContent } = await dynamicRouter.getMDXContent(source, filename);

return (
<div className="container">
<h2>{t('pages.404.title')}</h2>
<h3>{t('pages.404.description')}</h3>
</div>
<WithLayout layout="centered.hbs">
<MDXRenderer Component={MDXContent} />
</WithLayout>
canerakdas marked this conversation as resolved.
Show resolved Hide resolved
);
};

Expand Down
5 changes: 3 additions & 2 deletions components/withLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import LegacyIndexLayout from '@/layouts/IndexLayout';
import LegacyLearnLayout from '@/layouts/LearnLayout';
import AboutLayout from '@/layouts/New/About';
import BlogLayout from '@/layouts/New/Blog';
import CenteredLayout from '@/layouts/New/Centered';
ovflowd marked this conversation as resolved.
Show resolved Hide resolved
import DefaultLayout from '@/layouts/New/Default';
import DocsLayout from '@/layouts/New/Docs';
import HomeLayout from '@/layouts/New/Home';
import LearnLayout from '@/layouts/New/Learn';
import PostLayout from '@/layouts/New/Post';
import { ENABLE_WEBSITE_REDESIGN } from '@/next.constants.mjs';
Expand All @@ -28,13 +28,14 @@ const legacyLayouts = {
'index.hbs': LegacyIndexLayout,
'learn.hbs': LegacyLearnLayout,
'page.hbs': LegacyDefaultLayout,
'centered.hbs': LegacyDefaultLayout,
} satisfies Record<LegacyLayouts, FC>;

/** all the currently available layouts from website redesign */
const redesignLayouts = {
'about.hbs': AboutLayout,
'docs.hbs': DocsLayout,
'home.hbs': HomeLayout,
'centered.hbs': CenteredLayout,
'learn.hbs': LearnLayout,
'page.hbs': DefaultLayout,
'blog-post.hbs': PostLayout,
Expand Down
6 changes: 3 additions & 3 deletions layouts/New/Home.tsx → layouts/New/Centered.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import WithNavBar from '@/components/withNavBar';

import styles from './layouts.module.css';

const HomeLayout: FC<PropsWithChildren> = ({ children }) => (
const CenteredLayout: FC<PropsWithChildren> = ({ children }) => (
<>
<WithNavBar />

<div className={styles.homeLayout}>
<div className={styles.centeredLayout}>
<div className="glowingBackdrop" />
canerakdas marked this conversation as resolved.
Show resolved Hide resolved

<main>{children}</main>
Expand All @@ -19,4 +19,4 @@ const HomeLayout: FC<PropsWithChildren> = ({ children }) => (
</>
);

export default HomeLayout;
export default CenteredLayout;
20 changes: 19 additions & 1 deletion layouts/New/layouts.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}
}

.homeLayout {
.centeredLayout {
canerakdas marked this conversation as resolved.
Show resolved Hide resolved
@apply flex
w-full
items-center
Expand Down Expand Up @@ -106,6 +106,24 @@
}
}

&:nth-of-type(1)[role='status'] {
@apply max-w-xl
items-center
gap-2
text-center;

[role='button'] {
@apply mt-4
flex
items-center
gap-2;

svg {
@apply w-5;
}
}
}

&:nth-of-type(2) {
@apply flex
max-w-md
Expand Down
20 changes: 20 additions & 0 deletions pages/en/new-design/404.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
layout: centered.hbs
ovflowd marked this conversation as resolved.
Show resolved Hide resolved
permalink: false
title: 404
---

import { ArrowRightIcon } from '@heroicons/react/24/solid';

<section role='status'>
404

<h1 className="special">Page could not be found</h1>

<div>
Sorry, we couldn’t find the page you’re after! Try starting again from the
homepage.
</div>

<Button href="/">Back to Home<ArrowRightIcon /></Button>
</section>
2 changes: 1 addition & 1 deletion pages/en/new-design/index.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Run JavaScript Everywhere
layout: home.hbs
layout: centered.hbs
---

<section>
Expand Down
4 changes: 4 additions & 0 deletions styles/new/markdown.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ main {
dark:text-green-300;
}

&[role='button'] {
@apply xs:no-underline;
}

&:has(code) {
@apply xs:decoration-neutral-800
dark:xs:decoration-neutral-200;
Expand Down
5 changes: 3 additions & 2 deletions types/layouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export type Layouts =
| 'about.hbs'
| 'docs.hbs'
| 'home.hbs'
| 'centered.hbs'
| 'learn.hbs'
| 'page.hbs'
| 'blog-category.hbs'
Expand All @@ -17,4 +17,5 @@ export type LegacyLayouts =
| 'index.hbs'
| 'docs.hbs'
| 'download.hbs'
| 'page.hbs';
| 'page.hbs'
| 'centered.hbs';
Loading