|
| 1 | +import Head from 'next/head' |
| 2 | +import { ReactElement } from 'react' |
| 3 | +import useTranslation from 'next-translate/useTranslation' |
| 4 | + |
| 5 | +interface Props { |
| 6 | + /** |
| 7 | + * The meta description of the page. |
| 8 | + */ |
| 9 | + description?: string |
| 10 | + |
| 11 | + /** |
| 12 | + * The top-level title of the page. |
| 13 | + */ |
| 14 | + title?: string |
| 15 | +} |
| 16 | + |
| 17 | +/** |
| 18 | + * Renders the default meta tags. These can be over-ridden on a per-page basis. |
| 19 | + */ |
| 20 | +export const MetaTags = ({ |
| 21 | + description: optionalDescription, |
| 22 | + title: optionalTitle, |
| 23 | +}: Props): ReactElement => { |
| 24 | + const { t } = useTranslation('common') |
| 25 | + |
| 26 | + const titleTag = optionalTitle |
| 27 | + ? `${optionalTitle}${t('page_title_suffix')}` |
| 28 | + : `${t('page_title')}${t('page_title_suffix')}` |
| 29 | + const title = optionalTitle ? optionalTitle : t('page_title') |
| 30 | + const description = optionalDescription |
| 31 | + ? optionalDescription |
| 32 | + : t('meta_description') |
| 33 | + |
| 34 | + return ( |
| 35 | + <Head> |
| 36 | + <title>{titleTag}</title> |
| 37 | + <meta charSet="utf-8" /> |
| 38 | + <meta content={description} name="description" /> |
| 39 | + <meta content={title} key="title" property="og:title" /> |
| 40 | + <meta content={description} property="og:description" /> |
| 41 | + <meta |
| 42 | + content="https://string.is/twitter-cards/string-is.png" |
| 43 | + property="og:image" |
| 44 | + /> |
| 45 | + <meta content="summary" name="twitter:card" /> |
| 46 | + <meta content="@davemetrics" name="twitter:creator" /> |
| 47 | + <meta content="@string__is" name="twitter:site" /> |
| 48 | + <meta content={title} name="twitter:title" />) |
| 49 | + <meta content={description} name="twitter:description" /> |
| 50 | + <meta |
| 51 | + content="https://string.is/twitter-cards/string-is.png" |
| 52 | + name="twitter:image" |
| 53 | + /> |
| 54 | + <link |
| 55 | + href="/favicons/apple-touch-icon.png" |
| 56 | + rel="apple-touch-icon" |
| 57 | + sizes="180x180" |
| 58 | + /> |
| 59 | + <link |
| 60 | + href="/favicons/favicon-32x32.png" |
| 61 | + rel="icon" |
| 62 | + sizes="32x32" |
| 63 | + type="image/png" |
| 64 | + /> |
| 65 | + <link |
| 66 | + href="/favicons/favicon-16x16.png" |
| 67 | + rel="icon" |
| 68 | + sizes="16x16" |
| 69 | + type="image/png" |
| 70 | + /> |
| 71 | + <link href="/favicons/site.webmanifest" rel="manifest" /> |
| 72 | + <link |
| 73 | + color="#45b980" |
| 74 | + href="/favicons/safari-pinned-tab.svg" |
| 75 | + rel="mask-icon" |
| 76 | + /> |
| 77 | + <link href="/favicons/favicon.ico" rel="shortcut icon" /> |
| 78 | + <meta content="#45b980" name="msapplication-TileColor" /> |
| 79 | + <meta content="/favicons/browserconfig.xml" name="msapplication-config" /> |
| 80 | + <meta content="#ffffff" name="theme-color" /> |
| 81 | + </Head> |
| 82 | + ) |
| 83 | +} |
0 commit comments