Skip to content

Commit

Permalink
feat: added the page each by genius type and languages
Browse files Browse the repository at this point in the history
  • Loading branch information
kurone-kito committed Jun 21, 2021
1 parent e524aa1 commit fdc7de9
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/dantalion-web-playground/src/pages/[lang]/[genius].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Genius, types } from '@kurone-kito/dantalion-core';
import { locales } from '@kurone-kito/dantalion-i18n';
import type { GetStaticPaths, GetStaticProps, NextPage } from 'next';
import { useRouter } from 'next/router';
import Template from '../../components/templates/Template';
import type { PageProps } from '../_app';

/** Type definition of the required attributes. */
export type Query = {
/** Specifies the genius type. */
readonly genius?: Genius;
/** Specifies the language of this page. */
readonly lang?: string;
};

/** The index page component */
const Component: NextPage<PageProps> = ({ genius }) =>
useRouter().isFallback ? <>Loading...</> : <Template inner={genius} />;
Component.displayName = '[lang]';

/**
* Determine the attributes to assign to each path.
* @param context The context.
*/
export const getStaticProps: GetStaticProps<PageProps, Query> = async ({
params,
}) => ({ props: params ?? {} });

/** Determine the path to pre-render based on the data. */
export const getStaticPaths: GetStaticPaths<Query> = async () => ({
fallback: false,
paths: Object.keys(locales).flatMap((lang) =>
types.genius.map((genius) => ({ params: { genius, lang } }))
),
});

export default Component;

0 comments on commit fdc7de9

Please sign in to comment.