// [slug].js import Head from 'next/head'; import React, { useEffect } from 'react'; import { useDispatch } from 'react-redux'; import { Contained } from '../components/Contained'; import { RichBody } from '../components/RichBody'; import { CMS, NAVIGATION } from '../constants'; import { CmsApi, unslugify } from '../services/cms'; import { PageType, setPageType, SideMenuItem } from '../state/navigation'; import { ISplitPage } from '../types/cms'; import { generateTitle, generateURL } from '../utils/metadata'; interface IPath { params: { page: string }; } export async function getStaticPaths() { // Get paths to all pages // Hardcoded in navigation constants. // Contentful can edit entries but cannot add/remove // without touching code. const paths: IPath[] = Object.values(NAVIGATION.SIDE_MENU_ITEMS).map( item => ({ params: { page: item.href }, }), ); return { paths, fallback: true }; } export async function getStaticProps({ params }) { const href = params?.page ?? ''; const id = unslugify(String(href)); const cms = new CmsApi(); const page = await cms.fetchPageById(SideMenuItem[id] ?? ''); if (!page) { return { notFound: true }; } return { props: { page, href: `/${href}`, }, revalidate: CMS.CONTENT_REVALIDATE_RATE, }; } function Page({ page, href }: { page: ISplitPage | null; href: string }) { const dispatch = useDispatch(); useEffect(() => { dispatch(setPageType(PageType.NORMAL)); }, []); const pageTitle = generateTitle(page?.label); const pageDescription = page?.title; const pageURL = generateURL(href); return ( <> {pageTitle}
{page?.hero?.description

{page?.title}

); } export default Page;