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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
import { settings } from '@utils/config';
import Link from 'next/link';
import { useRouter } from 'next/router';
import Script from 'next/script';
import { useIntl } from 'react-intl';
import { BreadcrumbList, WithContext } from 'schema-dts';
import styles from './Breadcrumb.module.scss';
const Breadcrumb = ({ pageTitle }: { pageTitle: string }) => {
const intl = useIntl();
const router = useRouter();
const isHome = router.pathname === '/';
const isArticle = router.pathname.includes('/article/');
const isProject = router.pathname.includes('/projet/');
const isSubject = router.pathname.includes('/sujet/');
const isThematic = router.pathname.includes('/thematique/');
const getItems = () => {
return (
<>
<li className={styles.item}>
<Link href="/">
<a>
{intl.formatMessage({
defaultMessage: 'Home',
description: 'Breadcrumb: Home item',
id: 'Enij19',
})}
</a>
</Link>
</li>
{(isArticle || isThematic || isSubject) && (
<>
<li className={styles.item}>
<Link href="/blog">
<a>
{intl.formatMessage({
defaultMessage: 'Blog',
description: 'Breadcrumb: Blog item',
id: 'z0ic9c',
})}
</a>
</Link>
</li>
</>
)}
{isProject && (
<>
<li className={styles.item}>
<Link href="/projets">
<a>
{intl.formatMessage({
defaultMessage: 'Projects',
description: 'Breadcrumb: Projects item',
id: 'Igx3qp',
})}
</a>
</Link>
</li>
</>
)}
<li className="screen-reader-text">{pageTitle}</li>
</>
);
};
const getElementsSchema = () => {
const items = [];
const homepage: BreadcrumbList['itemListElement'] = {
'@type': 'ListItem',
position: 1,
name: intl.formatMessage({
defaultMessage: 'Home',
description: 'Breadcrumb: Home item',
id: 'Enij19',
}),
item: settings.url,
};
items.push(homepage);
if (isArticle || isThematic || isSubject) {
const blog: BreadcrumbList['itemListElement'] = {
'@type': 'ListItem',
position: 2,
name: intl.formatMessage({
defaultMessage: 'Blog',
description: 'Breadcrumb: Blog item',
id: 'z0ic9c',
}),
item: `${settings.url}/blog`,
};
items.push(blog);
}
if (isProject) {
const blog: BreadcrumbList['itemListElement'] = {
'@type': 'ListItem',
position: 2,
name: intl.formatMessage({
defaultMessage: 'Projects',
description: 'Breadcrumb: Projects item',
id: 'Igx3qp',
}),
item: `${settings.url}/projets`,
};
items.push(blog);
}
const currentPage: BreadcrumbList['itemListElement'] = {
'@type': 'ListItem',
position: items.length + 1,
name: pageTitle,
item: `${settings.url}${router.asPath}`,
};
items.push(currentPage);
return items;
};
const schemaJsonLd: WithContext<BreadcrumbList> = {
'@context': 'https://schema.org',
'@type': 'BreadcrumbList',
'@id': `${settings.url}/#breadcrumb`,
itemListElement: getElementsSchema(),
};
return (
<>
<Script
id="schema-breadcrumb"
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(schemaJsonLd) }}
/>
{!isHome && (
<nav id="breadcrumb" className={styles.wrapper}>
<span className="screen-reader-text">
{intl.formatMessage({
defaultMessage: 'You are here:',
description: 'Breadcrumb: You are here prefix',
id: '16zl9Z',
})}
</span>
<ol className={styles.list}>{getItems()}</ol>
</nav>
)}
</>
);
};
export default Breadcrumb;
|