All files / src/components/Seo Seo.tsx

100% Statements 8/8
100% Branches 14/14
100% Functions 1/1
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59        13x                 179x 179x 179x   179x 179x 179x   179x                                                                          
import { Helmet } from 'react-helmet';
import { useTranslation } from 'react-i18next';
import { makeJsonLd } from '../../utils/seo';
 
const BASE_URL = 'https://jo2024.mkcodecreations.dev';
 
interface SeoProps {
  title?: string;
  description?: string;
  noIndex?: boolean;
}
 
function Seo({ title, description, noIndex }: SeoProps) {
  const { t, i18n } = useTranslation();
  const locale = i18n.language;           
  const url    = `${BASE_URL}/`;
 
  const defaultTitle       = t('seo.title');
  const defaultDescription = t('seo.description');
  const jsonLd             = makeJsonLd(t);
 
  return (
    <Helmet>
      {/* Lang attribute */}
      <html lang={locale} />
 
      {/* Title & Description */}
      <title>{title ?? defaultTitle}</title>
      <meta name="description" content={description ?? defaultDescription} />
      <meta name="keywords" content={t('seo.keywords')} />
      <meta name="robots" content={noIndex ? 'noindex, nofollow' : 'index, follow'} />
      <meta http-equiv="Content-Language" content="fr" />
 
      {/* Canonical */}
      <link rel="canonical" href={url} />
 
      {/* Open Graph */}
      <meta property="og:type"        content="website" />
      <meta property="og:url"         content={url} />
      <meta property="og:title"       content={title ?? defaultTitle} />
      <meta property="og:description" content={description ?? defaultDescription} />
      <meta property="og:image"       content={`${BASE_URL}/assets/og-image.png`} />
 
      {/* Twitter Card */}
      <meta name="twitter:card"        content="summary_large_image" />
      <meta name="twitter:title"       content={title ?? defaultTitle} />
      <meta name="twitter:description" content={description ?? defaultDescription} />
      <meta name="twitter:image"       content={`${BASE_URL}/assets/twitter-card.png`} />
 
      {/* Structured Data */}
      <script type="application/ld+json"
        dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
      />
    </Helmet>
  );
}
 
export default Seo;