Skip to content

Commit

Permalink
Add dynamic pages (#83)
Browse files Browse the repository at this point in the history
* Add dynamic pages

* add title
  • Loading branch information
Lucieo authored Feb 23, 2024
1 parent 2b90453 commit 885152d
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions web/pages/[id].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react'
import { SSRConfig } from 'next-i18next'
import { GetServerSideProps } from 'next'
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
import { Heading, Box } from '@chakra-ui/react'
import MarkdownRenderer from '~components/MarkdownRenderer'
import { ROUTE_USE_POLICY } from '~constants'
import { Page } from '~typings/api'
import { getPage } from '~utils/page'
import { NextSeo } from 'next-seo'
import { useTranslation } from 'next-i18next'

interface Props {
page: Page
}

const OtherPages = ({ page }: Props) => {
const { t } = useTranslation('common')
return (
<>
<NextSeo title={page.title} />
<Heading
as="h1"
textStyle="h1"
layerStyle="mainTitle"
textAlign="center"
maxW="container.sm"
mx="auto"
>
{page.title}
</Heading>
<Box maxW="container.sm" mx="auto">
<MarkdownRenderer>{page.text}</MarkdownRenderer>
</Box>
</>
)
}

export const getServerSideProps: GetServerSideProps<SSRConfig> = async ({
locale,
params,
}) => {
const page = await getPage(params.id)
if (!page) return { redirect: { destination: '/', permanent: false } }

return {
props: {
page,
...(await serverSideTranslations(locale, ['common'])),
},
}
}

export default OtherPages

0 comments on commit 885152d

Please sign in to comment.