| 1 | import Head from 'next/head' |
| 2 | import { useRouter } from 'next/router' |
| 3 | import { Footer } from 'components/Footer' |
| 4 | import { Header, ItemSlug } from 'components/Header' |
| 5 | import { generateTitle } from 'utils/title' |
| 6 | import { absoluteUrl } from 'utils/url' |
| 7 | |
| 8 | export type LayoutProps = React.PropsWithChildren<{ |
| 9 | activeItem?: ItemSlug |
| 10 | canonical?: string |
| 11 | description?: string |
| 12 | image?: string |
| 13 | noIndex?: boolean |
| 14 | title?: string | string[] |
| 15 | type?: string |
| 16 | }> |
| 17 | |
| 18 | const defaultDescription = |
| 19 | 'Marp (also known as the Markdown Presentation Ecosystem) provides an intuitive experience for creating beautiful slide decks. You only have to focus on writing your story in a Markdown document.' |
| 20 | |
| 21 | export const Layout: React.FC<LayoutProps> = ({ |
| 22 | activeItem, |
| 23 | canonical: _canonical, |
| 24 | children, |
| 25 | description = defaultDescription, |
| 26 | image: _image, |
| 27 | noIndex, |
| 28 | title: _title, |
| 29 | type = 'article', |
| 30 | }) => { |
| 31 | const router = useRouter() |
| 32 | |
| 33 | const canonical = absoluteUrl(_canonical || router.asPath).href |
| 34 | const image = _image || '/assets/og-image.png' |
| 35 | const title = typeof _title === 'string' ? _title : generateTitle(_title) |
| 36 | |
| 37 | return ( |
| 38 | <> |
| 39 | <Head> |
| 40 | <title key="title">{title}</title> |
| 41 | {description && ( |
| 42 | <> |
| 43 | <meta name="description" key="description" content={description} /> |
| 44 | <meta |
| 45 | property="og:description" |
| 46 | key="og:description" |
| 47 | content={description} |
| 48 | /> |
| 49 | </> |
| 50 | )} |
| 51 | {canonical && ( |
| 52 | <> |
| 53 | <link rel="canonical" key="canonical" href={canonical} /> |
| 54 | <meta property="og:url" key="og:url" content={canonical} /> |
| 55 | </> |
| 56 | )} |
| 57 | <meta property="og:title" key="og:title" content={title} /> |
| 58 | <meta property="og:type" key="og:type" content={type} /> |
| 59 | <meta |
| 60 | property="og:image" |
| 61 | key="og:image" |
| 62 | content={absoluteUrl(image).href} |
| 63 | /> |
| 64 | <meta |
| 65 | property="twitter:card" |
| 66 | key="twitter:card" |
| 67 | content={ |
| 68 | type === 'website' || _image ? 'summary_large_image' : 'summary' |
| 69 | } |
| 70 | /> |
| 71 | {noIndex && <meta name="robots" content="noindex,nofollow" />} |
| 72 | </Head> |
| 73 | <Header activeItem={activeItem} /> |
| 74 | <main className="relative mt-16 md:mt-20"> |
| 75 | {children} |
| 76 | <style jsx>{` |
| 77 | main { |
| 78 | min-height: calc(100vh - 8.5rem); |
| 79 | } |
| 80 | |
| 81 | @screen md { |
| 82 | main { |
| 83 | min-height: calc(100vh - 9.5rem); |
| 84 | } |
| 85 | } |
| 86 | `}</style> |
| 87 | </main> |
| 88 | <Footer /> |
| 89 | </> |
| 90 | ) |
| 91 | } |
| 92 |