summaryrefslogtreecommitdiffstats
path: root/src/components/Breadcrumb/Breadcrumb.tsx
blob: 77e7c08afe4afc6df0644824bea7ca50cad6dc6b (plain)
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
import { t } from '@lingui/macro';
import Head from 'next/head';
import Link from 'next/link';
import { useRouter } from 'next/router';
import styles from './Breadcrumb.module.scss';

const Breadcrumb = ({ pageTitle }: { pageTitle: string }) => {
  const router = useRouter();

  const isHome = router.pathname === '/';
  const isArticle = router.pathname.includes('/article/');
  const isThematic = router.pathname.includes('/thematique/');
  const isSubject = router.pathname.includes('/sujet/');

  const getItems = () => {
    return (
      <>
        <Head>
          <script type="application/ld+json">{}</script>
        </Head>
        <li className={styles.item}>
          <Link href="/">
            <a>{t`Home`}</a>
          </Link>
        </li>
        {(isArticle || isThematic || isSubject) && (
          <>
            <li className={styles.item}>
              <Link href="/blog">
                <a>{t`Blog`}</a>
              </Link>
            </li>
          </>
        )}
      </>
    );
  };

  return (
    <>
      {!isHome && (
        <nav className={styles.wrapper}>
          <span className="screen-reader-text">{t`You are here:`}</span>
          <ol className={styles.list}>{getItems()}</ol>
        </nav>
      )}
    </>
  );
};

export default Breadcrumb;