diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-05-17 22:48:41 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-05-17 22:48:41 +0200 |
| commit | 271ef6debaca7ed9a01829dcef3a37e90a2dff05 (patch) | |
| tree | aa1513b40e7020a44cfcaaedc3a33d39ecfb8af7 /src/components/templates/layout/layout.tsx | |
| parent | 4e53a8654441481029746ff4e35a4a19c8d83709 (diff) | |
chore: use persistent layout
It prevents to rerender the common components between pages (header,
footer...).
Diffstat (limited to 'src/components/templates/layout/layout.tsx')
| -rw-r--r-- | src/components/templates/layout/layout.tsx | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/src/components/templates/layout/layout.tsx b/src/components/templates/layout/layout.tsx index 3eb02ee..559eaed 100644 --- a/src/components/templates/layout/layout.tsx +++ b/src/components/templates/layout/layout.tsx @@ -9,18 +9,13 @@ import Main from '@components/atoms/layout/main'; import NoScript from '@components/atoms/layout/no-script'; import Footer, { type FooterProps } from '@components/organisms/layout/footer'; import Header, { type HeaderProps } from '@components/organisms/layout/header'; +import { type NextPageWithLayoutOptions } from '@ts/types/app'; import useScrollPosition from '@utils/hooks/use-scroll-position'; import useSettings from '@utils/hooks/use-settings'; import Script from 'next/script'; -import { FC, ReactNode, useState } from 'react'; +import { FC, ReactElement, ReactNode, useState } from 'react'; import { useIntl } from 'react-intl'; -import { - BreadcrumbList, - Person, - SearchAction, - WebSite, - WithContext, -} from 'schema-dts'; +import { Person, SearchAction, WebSite, WithContext } from 'schema-dts'; import styles from './layout.module.scss'; export type QueryAction = SearchAction & { @@ -29,17 +24,17 @@ export type QueryAction = SearchAction & { export type LayoutProps = Pick<HeaderProps, 'isHome'> & { /** - * The breadcrumb JSON schema. - */ - breadcrumbSchema: BreadcrumbList['itemListElement'][]; - /** * The layout main content. */ children: ReactNode; /** - * Set additional classnames to the article element. + * Determine if article has a comments section. + */ + withExtraPadding?: boolean; + /** + * Determine if article should use grid. Default: false. */ - className?: string; + useGrid?: boolean; }; /** @@ -48,14 +43,16 @@ export type LayoutProps = Pick<HeaderProps, 'isHome'> & { * Render the base layout used by all pages. */ const Layout: FC<LayoutProps> = ({ - breadcrumbSchema, children, + withExtraPadding = false, isHome, - ...props + useGrid = false, }) => { const intl = useIntl(); const { website } = useSettings(); const { baseline, copyright, locales, name, picture, url } = website; + const articleGridClass = useGrid ? 'article--grid' : ''; + const articleCommentsClass = withExtraPadding ? 'article--padding' : ''; const skipToContent = intl.formatMessage({ defaultMessage: 'Skip to content', @@ -188,11 +185,6 @@ const Layout: FC<LayoutProps> = ({ type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(brandingSchema) }} /> - <Script - id="schema-breadcrumb" - type="application/ld+json" - dangerouslySetInnerHTML={{ __html: JSON.stringify(breadcrumbSchema) }} - /> <noscript> <div className={styles['noscript-spacing']}></div> </noscript> @@ -211,7 +203,11 @@ const Layout: FC<LayoutProps> = ({ className={styles.header} /> <Main id="main" className={styles.main}> - <article {...props}>{children}</article> + <article + className={`${styles[articleGridClass]} ${styles[articleCommentsClass]}`} + > + {children} + </article> </Main> <Footer copyright={copyrightData} @@ -227,4 +223,18 @@ const Layout: FC<LayoutProps> = ({ ); }; +/** + * Get the global layout. + * + * @param {ReactElement} page - A page. + * @param {boolean} [isHome] - Determine if it is the homepage. + * @returns A page wrapped with the global layout. + */ +export const getLayout = ( + page: ReactElement, + props: NextPageWithLayoutOptions +) => { + return <Layout {...props}>{page}</Layout>; +}; + export default Layout; |
