-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added the page each by genius type and languages
- Loading branch information
1 parent
e524aa1
commit fdc7de9
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
packages/dantalion-web-playground/src/pages/[lang]/[genius].tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |