diff --git a/src/components/Blog/Card/index.tsx b/src/components/Blog/Card/index.tsx index 59431e73b..64ca92730 100644 --- a/src/components/Blog/Card/index.tsx +++ b/src/components/Blog/Card/index.tsx @@ -6,7 +6,7 @@ import { calculateReadingTimeInMin } from '@/components/Blog/utils/calculateRead import Tags from '@/components/Blog/Tags' import CategoryIcon from '@/public/images/Blog/category-icon.svg' import { isAsset } from '@/lib/typeGuards' -import { type BlogPostEntry } from '@/components/Blog/Post' +import type { BlogPostEntry } from '@/config/types' import { AppRoutes } from '@/config/routes' const Card = (props: BlogPostEntry) => { diff --git a/src/components/Blog/FeaturedPost/index.tsx b/src/components/Blog/FeaturedPost/index.tsx index 4ea943dba..b0527b7a3 100644 --- a/src/components/Blog/FeaturedPost/index.tsx +++ b/src/components/Blog/FeaturedPost/index.tsx @@ -4,7 +4,7 @@ import { Box, Grid, Link, Typography } from '@mui/material' import css from './styles.module.css' import { formatBlogDate } from '@/components/Blog/utils/formatBlogDate' import { calculateReadingTimeInMin } from '@/components/Blog/utils/calculateReadingTime' -import { type BlogPostEntry } from '@/components/Blog/Post' +import type { BlogPostEntry } from '@/config/types' import { isAsset } from '@/lib/typeGuards' import CategoryIcon from '@/public/images/Blog/category-icon.svg' import { AppRoutes } from '@/config/routes' diff --git a/src/components/Blog/Post/index.tsx b/src/components/Blog/Post/index.tsx index eaf42b67f..1afc9aae3 100644 --- a/src/components/Blog/Post/index.tsx +++ b/src/components/Blog/Post/index.tsx @@ -1,7 +1,7 @@ import Image from 'next/image' import { Box, Button, Container, Divider, Grid, Typography } from '@mui/material' import { type Entry } from 'contentful' -import type { TypeAuthorSkeleton, TypePostSkeleton } from '@/contentful/types' +import type { TypeAuthorSkeleton } from '@/contentful/types' import { formatBlogDate } from '@/components/Blog/utils/formatBlogDate' import { calculateReadingTimeInMin } from '@/components/Blog/utils/calculateReadingTime' import { isAsset, isEntryTypeAuthor, isEntryTypePost } from '@/lib/typeGuards' @@ -20,12 +20,13 @@ import css from '../styles.module.css' import { PRESS_RELEASE_TAG, containsTag } from '@/lib/containsTag' import { COMMS_EMAIL } from '@/config/constants' import { useBlogPost } from '@/hooks/useBlogPost' -import type { InferGetStaticPropsType } from 'next' -import type { getStaticProps } from '@/pages/blog/[slug]' +import type { BlogPostEntry } from '@/config/types' -export type BlogPostEntry = Entry +export type BlogPostProps = { + blogPost: BlogPostEntry +} -const BlogPost = ({ blogPost }: InferGetStaticPropsType) => { +const BlogPost = ({ blogPost }: BlogPostProps) => { const { data: post } = useBlogPost(blogPost.sys.id, blogPost) const { title, excerpt, content, coverImage, authors, tags, category, date, relatedPosts, metaTags } = post.fields diff --git a/src/components/common/Page/index.tsx b/src/components/common/Page/index.tsx index de9015e46..4b4ec7f85 100644 --- a/src/components/common/Page/index.tsx +++ b/src/components/common/Page/index.tsx @@ -3,7 +3,11 @@ import { isEntryType, isEntryTypeBaseBlock } from '@/lib/typeGuards' import MetaTags from '@/components/common/MetaTagsContentful' import { type LandingPageEntry } from '@/config/types' -const Page = ({ landingPage }: { landingPage: LandingPageEntry }) => { +export type LandingPageProps = { + landingPage: LandingPageEntry +} + +const Page = ({ landingPage }: LandingPageProps) => { const { metaTags, content } = landingPage.fields return ( diff --git a/src/config/types.ts b/src/config/types.ts index ffe666641..ff60cd172 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -13,4 +13,5 @@ export type ButtonEntry = Entry export type LandingPageEntry = Entry export type PressRoomEntry = Entry export type BlogHomeEntry = Entry +export type BlogPostEntry = Entry export type PostEntryCollection = EntryCollection diff --git a/src/hooks/useBlogPost.ts b/src/hooks/useBlogPost.ts index 36f0fcd50..acba521ff 100644 --- a/src/hooks/useBlogPost.ts +++ b/src/hooks/useBlogPost.ts @@ -1,6 +1,6 @@ import useSWR from 'swr' import client from '@/lib/contentful' -import { type BlogPostEntry } from '@/components/Blog/Post' +import type { BlogPostEntry } from '@/config/types' import { type TypePostSkeleton } from '@/contentful/types' const postFetcher = (id: string) => client.getEntry(id) diff --git a/src/lib/contentful/__test__/isPressRelease.test.ts b/src/lib/contentful/__test__/isPressRelease.test.ts index 31240d9ca..d00a192e2 100644 --- a/src/lib/contentful/__test__/isPressRelease.test.ts +++ b/src/lib/contentful/__test__/isPressRelease.test.ts @@ -1,5 +1,5 @@ import { isPressReleasePost, isPublishedPressRelease } from '@/lib/contentful/isPressRelease' -import type { BlogPostEntry } from '@/components/Blog/Post' +import type { BlogPostEntry } from '@/config/types' import type { TypePostFields } from '@/contentful/types' describe('isPressReleasePost', () => { diff --git a/src/lib/contentful/isDraft.ts b/src/lib/contentful/isDraft.ts index 146e8ee1e..0350c6366 100644 --- a/src/lib/contentful/isDraft.ts +++ b/src/lib/contentful/isDraft.ts @@ -1,3 +1,3 @@ -import type { BlogPostEntry } from '@/components/Blog/Post' +import type { BlogPostEntry } from '@/config/types' export const isDraft = (post: BlogPostEntry) => post.fields.isDraft diff --git a/src/lib/contentful/isPressRelease.ts b/src/lib/contentful/isPressRelease.ts index 6c49600c4..e38c71181 100644 --- a/src/lib/contentful/isPressRelease.ts +++ b/src/lib/contentful/isPressRelease.ts @@ -1,6 +1,6 @@ import { containsTag, PRESS_RELEASE_TAG } from '@/lib/containsTag' import { isDraft } from '@/lib/contentful/isDraft' -import type { BlogPostEntry } from '@/components/Blog/Post' +import type { BlogPostEntry } from '@/config/types' export const isPressReleasePost = (post: BlogPostEntry) => containsTag(post.fields.tags, PRESS_RELEASE_TAG) diff --git a/src/pages/[slug].tsx b/src/pages/[slug].tsx index 285837146..e5248af67 100644 --- a/src/pages/[slug].tsx +++ b/src/pages/[slug].tsx @@ -1,23 +1,15 @@ -import type { GetStaticPaths, GetStaticProps, InferGetStaticPropsType } from 'next' +import type { GetStaticPaths, GetStaticProps, InferGetStaticPropsType, NextPage } from 'next' import client from '@/lib/contentful' import { type TypeLandingPageSkeleton } from '@/contentful/types' -import Page from '@/components/common/Page' -import { type LandingPageEntry } from '@/config/types' -import PageLayout from '@/components/common/PageLayout' -import type { ReactElement } from 'react' -import type { NextPageWithLayout } from '@/pages/_app' +import Page, { type LandingPageProps } from '@/components/common/Page' -const LandingPage: NextPageWithLayout> = (props) => { +const LandingPage: NextPage> = (props) => { if (!props.landingPage) return null return } -LandingPage.getLayout = function getLayout(page: ReactElement) { - return {page} -} - -export const getStaticProps: GetStaticProps<{ landingPage: LandingPageEntry }> = async ({ params }) => { +export const getStaticProps: GetStaticProps = async ({ params }) => { const slug = params?.slug as string const landingPageEntries = await client.getEntries({ diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 5857a5d5b..fbf5efa38 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -16,6 +16,7 @@ import { CookieBanner } from '@/components/common/CookieBanner' import { theme } from '@/styles/theme' import '@/styles/globals.css' +import PageLayout from '@/components/common/PageLayout' import { useGa } from '@/hooks/useGa' import useHotjar from '@/hooks/useHotjar' import DOMPurify from 'isomorphic-dompurify' @@ -54,8 +55,8 @@ const App = ({ Component: NextPageWithLayout emotionCache?: EmotionCache }): ReactElement => { - // Use the layout defined at the page level, if available - const getLayout = Component.getLayout ?? ((page) => page) + // Use the layout defined at the page level, if available or the default layout + const getLayout = Component.getLayout ?? ((page) => {page}) return ( diff --git a/src/pages/blog/[slug].tsx b/src/pages/blog/[slug].tsx index 02646aff4..8c7fc3da4 100644 --- a/src/pages/blog/[slug].tsx +++ b/src/pages/blog/[slug].tsx @@ -1,22 +1,15 @@ -import type { ReactElement } from 'react' -import type { NextPageWithLayout } from '@/pages/_app' -import BlogPost from '@/components/Blog/Post' -import PageLayout from '@/components/common/PageLayout' +import BlogPost, { type BlogPostProps } from '@/components/Blog/Post' import { type TypePostSkeleton } from '@/contentful/types' import client from '@/lib/contentful' -import type { GetStaticProps, InferGetStaticPropsType } from 'next' +import type { GetStaticProps, InferGetStaticPropsType, NextPage } from 'next' -const Page: NextPageWithLayout> = (props) => { +const Page: NextPage> = (props) => { if (!props.blogPost) return null return } -Page.getLayout = function getLayout(page: ReactElement) { - return {page} -} - -export const getStaticProps: GetStaticProps = async ({ params }) => { +export const getStaticProps: GetStaticProps = async ({ params }) => { const slug = params?.slug as string const content = await client.getEntries({ diff --git a/src/pages/blog/index.tsx b/src/pages/blog/index.tsx index c62eacbae..7d28f9c32 100644 --- a/src/pages/blog/index.tsx +++ b/src/pages/blog/index.tsx @@ -2,19 +2,12 @@ import client from '@/lib/contentful' import BlogHome, { type BlogHomeProps } from '@/components/Blog/BlogHome' import type { TypeBlogHomeSkeleton, TypePostSkeleton } from '@/contentful/types' import { isEntryTypePost } from '@/lib/typeGuards' -import type { NextPageWithLayout } from '@/pages/_app' -import type { ReactElement } from 'react' -import PageLayout from '@/components/common/PageLayout' -import type { GetStaticProps, InferGetStaticPropsType } from 'next' +import type { GetStaticProps, InferGetStaticPropsType, NextPage } from 'next' -const Blog: NextPageWithLayout> = (props) => { +const Blog: NextPage> = (props) => { return } -Blog.getLayout = function getLayout(page: ReactElement) { - return {page} -} - export const getStaticProps: GetStaticProps = async () => { const allPosts = await client.getEntries({ content_type: 'post', diff --git a/src/pages/press.tsx b/src/pages/press.tsx index b403c6d7e..5b1e0bc9d 100644 --- a/src/pages/press.tsx +++ b/src/pages/press.tsx @@ -2,19 +2,12 @@ import client from '@/lib/contentful' import PressRoom, { type PressRoomProps } from '@/components/Pressroom' import type { TypePressRoomSkeleton, TypePostSkeleton } from '@/contentful/types' import { fetchTotalAssets } from '@/hooks/useSafeStats' -import type { ReactElement } from 'react' -import PageLayout from '@/components/common/PageLayout' -import type { NextPageWithLayout } from '@/pages/_app' -import type { GetStaticProps, InferGetStaticPropsType } from 'next' +import type { GetStaticProps, InferGetStaticPropsType, NextPage } from 'next' -const PressroomPage: NextPageWithLayout> = (props) => { +const PressroomPage: NextPage> = (props) => { return } -PressroomPage.getLayout = function getLayout(page: ReactElement) { - return {page} -} - export const getStaticProps: GetStaticProps = async () => { const allPosts = await client.getEntries({ content_type: 'post',