|
| 1 | +import { Helmet } from 'react-helmet-async'; |
| 2 | +import { useTranslation } from 'react-i18next'; |
| 3 | + |
| 4 | +interface SeoHeadProps { |
| 5 | + /** Page-specific title; the localized brand suffix is appended automatically. */ |
| 6 | + title: string; |
| 7 | + /** Plain-text description for <meta name="description"> and og:description. */ |
| 8 | + description?: string; |
| 9 | + /** Absolute image URL for og:image (e.g. a Supabase Storage URL). */ |
| 10 | + image?: string; |
| 11 | +} |
| 12 | + |
| 13 | +// Site-wide social-share fallback used when a page has no image of its own. |
| 14 | +const DEFAULT_OG_IMAGE = '/twitter-card.png'; |
| 15 | + |
| 16 | +/** |
| 17 | + * Sets per-page document head (title + description + Open Graph) via |
| 18 | + * react-helmet-async. On live visits this keeps the browser-tab title and |
| 19 | + * social-share metadata correct per route; at build time the prerender step |
| 20 | + * (scripts/prerender.mjs) waits for these tags before snapshotting, so AI |
| 21 | + * crawlers and search engines see unique metadata per page instead of the |
| 22 | + * static index.html shell. |
| 23 | + */ |
| 24 | +const SeoHead = ({ title, description, image }: SeoHeadProps) => { |
| 25 | + const { t } = useTranslation(); |
| 26 | + const suffix = t('meta.titleSuffix'); |
| 27 | + const fullTitle = title ? `${title} | ${suffix}` : suffix; |
| 28 | + |
| 29 | + return ( |
| 30 | + <Helmet> |
| 31 | + <title>{fullTitle}</title> |
| 32 | + <meta property="og:title" content={fullTitle} /> |
| 33 | + {description && <meta name="description" content={description} />} |
| 34 | + {description && <meta property="og:description" content={description} />} |
| 35 | + <meta property="og:image" content={image || DEFAULT_OG_IMAGE} /> |
| 36 | + <meta name="twitter:image" content={image || DEFAULT_OG_IMAGE} /> |
| 37 | + </Helmet> |
| 38 | + ); |
| 39 | +}; |
| 40 | + |
| 41 | +export default SeoHead; |
0 commit comments