Add Universe categories

This commit is contained in:
Marcus Blättermann 2022-11-17 00:30:00 +01:00
parent 7dac26df38
commit cefbb3d203
No known key found for this signature in database
GPG Key ID: A1E1F04008AC450D
2 changed files with 48 additions and 0 deletions

View File

@ -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]))
)

View File

@ -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<ParsedUrlQuery> = async () => {
return {
paths: universe.categories.flatMap((category) =>
category.items.map((item) => `/universe/category/${item.id}`)
),
fallback: false,
}
}
export const getStaticProps: GetStaticProps<PropsPageBase, ParsedUrlQuery> = 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,
},
}
}