@@ -3,13 +3,35 @@ import Head from 'next/head';
3
3
import Navbar from '../Navbar' ;
4
4
import Footer from '../Footer' ;
5
5
6
- export default function Layout ( { children, pageTitle } ) {
6
+ const generateBreadcrumbs = crumbs => {
7
+ const BASE_URL = 'https://khendrikse.github.io/' ;
8
+
9
+ const json = {
10
+ '@context' : 'https://schema.org/' ,
11
+ '@type' : 'BreadcrumbList' ,
12
+ itemListElement : crumbs . map ( ( { name, item } , index ) => ( {
13
+ '@type' : 'ListItem' ,
14
+ position : index + 1 ,
15
+ name,
16
+ item : `${ BASE_URL } ${ item } `
17
+ } ) )
18
+ } ;
19
+
20
+ return JSON . stringify ( json ) ;
21
+ } ;
22
+
23
+ export default function Layout ( { children, pageTitle, breadcrumbs } ) {
7
24
return (
8
25
< >
9
26
< Head >
10
27
< meta name = 'viewport' content = 'width=device-width, initial-scale=1' />
11
28
< meta name = 'description' content = 'Online space, blog and portfolio' />
12
29
< title > { pageTitle } </ title >
30
+ { breadcrumbs && (
31
+ < script type = 'application/ld+json' >
32
+ { generateBreadcrumbs ( breadcrumbs ) }
33
+ </ script >
34
+ ) }
13
35
</ Head >
14
36
< div className = 'wrapper' >
15
37
< section className = 'layout' >
@@ -24,5 +46,8 @@ export default function Layout({ children, pageTitle }) {
24
46
25
47
Layout . propTypes = {
26
48
children : PropTypes . element ,
27
- pageTitle : PropTypes . string
49
+ pageTitle : PropTypes . string ,
50
+ breadcrumbs : PropTypes . arrayOf (
51
+ PropTypes . shape ( { name : PropTypes . string , item : PropTypes . string } )
52
+ )
28
53
} ;
0 commit comments