From e0ca8a0f563463b927997334e9fa29d0ba17c3d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Bl=C3=A4ttermann?= Date: Tue, 15 Nov 2022 01:49:53 +0100 Subject: [PATCH] Add model pages --- website/meta/recordLanguages.tsx | 7 ++++ website/pages/[...listPathPage].tsx | 10 +++-- website/pages/models/[slug].tsx | 59 +++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 website/meta/recordLanguages.tsx create mode 100644 website/pages/models/[slug].tsx diff --git a/website/meta/recordLanguages.tsx b/website/meta/recordLanguages.tsx new file mode 100644 index 000000000..6555a4650 --- /dev/null +++ b/website/meta/recordLanguages.tsx @@ -0,0 +1,7 @@ +import models from './languages.json' + +const recordLanguages = Object.fromEntries( + models.languages.map((language, index) => [language.code, language]) +) + +export default recordLanguages diff --git a/website/pages/[...listPathPage].tsx b/website/pages/[...listPathPage].tsx index 1ab7850d6..cbee7b4f6 100644 --- a/website/pages/[...listPathPage].tsx +++ b/website/pages/[...listPathPage].tsx @@ -17,9 +17,7 @@ type ApiDetails = { trainable: string | null } -type PropsPage = { - mdx: MDXRemoteSerializeResult - +export type PropsPageBase = { /** * TODO: This is only here for legacy support of the old code base * It should be refactort to pass the file path and page path instead. @@ -28,10 +26,14 @@ type PropsPage = { sectionTitle: string | null theme: string | null section: string - apiDetails: ApiDetails isIndex: boolean } +export type PropsPage = PropsPageBase & { + mdx: MDXRemoteSerializeResult + apiDetails: ApiDetails +} + const PostPage = ({ mdx: mdx, ...props }: PropsPage) => { return ( diff --git a/website/pages/models/[slug].tsx b/website/pages/models/[slug].tsx new file mode 100644 index 000000000..1698d6382 --- /dev/null +++ b/website/pages/models/[slug].tsx @@ -0,0 +1,59 @@ +import type { GetStaticPaths, GetStaticProps } from 'next' +import models from '../../meta/languages.json' +import recordSection from '../../meta/recordSections' +import recordLanguages from '../../meta/recordLanguages' +import Layout from '../../src/components/layout' +import { PropsPageBase } from '../[...listPath]' + +type PropsPageModel = PropsPageBase & { + next: { title: string; slug: string } | null + meta: { models?: ReadonlyArray; example?: string; hasExamples?: boolean } +} + +const PostPageModel = (props: PropsPageModel) => { + return +} + +export default PostPageModel + +export const getStaticPaths: GetStaticPaths<{ slug: string }> = async () => { + return { + paths: models.languages + .filter(({ models }) => models && models.length) + .map((language) => `/models/${language.code}`), + fallback: false, + } +} + +export const getStaticProps: GetStaticProps< + PropsPageModel, + { + slug: string + } +> = async (args) => { + if (args.params === undefined) { + return { notFound: true } + } + + const language = recordLanguages[args.params.slug] + + return { + props: { + id: language.code, + slug: `/${['models', language.code].join('/')}`, + isIndex: false, + title: language.name, + section: 'models', + sectionTitle: recordSection.models.title, + theme: recordSection.models.theme, + next: language.next + ? { title: language.next.name, slug: `/models/${language.next.code}` } + : null, + meta: { + models: language.models || null, + example: language.example || null, + hasExamples: language.has_examples || null, + }, + }, + } +}