From cefbb3d203289de17386cf58e34905473648561f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Bl=C3=A4ttermann?= Date: Thu, 17 Nov 2022 00:30:00 +0100 Subject: [PATCH] Add Universe categories --- website/meta/recordUniverse.tsx | 5 +++ website/pages/universe/category/[slug].tsx | 43 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 website/meta/recordUniverse.tsx create mode 100644 website/pages/universe/category/[slug].tsx diff --git a/website/meta/recordUniverse.tsx b/website/meta/recordUniverse.tsx new file mode 100644 index 000000000..3216b5672 --- /dev/null +++ b/website/meta/recordUniverse.tsx @@ -0,0 +1,5 @@ +import universe from './universe.json' + +export const recordUniverseCategories = Object.fromEntries( + universe.categories.flatMap((category) => category.items.map((item) => [item.id, item])) +) diff --git a/website/pages/universe/category/[slug].tsx b/website/pages/universe/category/[slug].tsx new file mode 100644 index 000000000..b110213d1 --- /dev/null +++ b/website/pages/universe/category/[slug].tsx @@ -0,0 +1,43 @@ +import { GetStaticPaths, GetStaticProps } from 'next' +import recordSections from '../../../meta/recordSections' +import { recordUniverseCategories } from '../../../meta/recordUniverse' +import universe from '../../../meta/universe.json' +import Layout from '../../../src/templates' +import { PropsPageBase } from '../../[...listPathPage]' + +type ParsedUrlQuery = { + slug: string +} + +export default Layout + +export const getStaticPaths: GetStaticPaths = async () => { + return { + paths: universe.categories.flatMap((category) => + category.items.map((item) => `/universe/category/${item.id}`) + ), + fallback: false, + } +} + +export const getStaticProps: GetStaticProps = async (args) => { + if (!args.params) { + return { notFound: true } + } + + const item = recordUniverseCategories[args.params.slug] + + return { + props: { + id: item.id, + title: item.title, + teaser: item.description, + slug: `/universe/category/${args.params.slug}`, + isIndex: false, + data: { ...item, isCategory: true }, + section: 'universe', + sectionTitle: recordSections.universe.title, + theme: recordSections.universe.theme, + }, + } +}