Skip to content

Commit 9192682

Browse files
committed
add bcrumbs everywhere
1 parent 49b47ed commit 9192682

File tree

7 files changed

+41
-31
lines changed

7 files changed

+41
-31
lines changed

components/Layout/index.js

+5-23
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,19 @@
11
import PropTypes from 'prop-types';
22
import Head from 'next/head';
3+
import generateBreadcrumbs from 'helpers/generate-breadcrumbs';
34
import Navbar from '../Navbar';
45
import Footer from '../Footer';
56

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+
export default function Layout({ children, pageTitle, breadcrumbs = [] }) {
248
return (
259
<>
2610
<Head>
2711
<meta name='viewport' content='width=device-width, initial-scale=1' />
2812
<meta name='description' content='Online space, blog and portfolio' />
2913
<title>{pageTitle}</title>
30-
{breadcrumbs && (
31-
<script type='application/ld+json'>
32-
{generateBreadcrumbs(breadcrumbs)}
33-
</script>
34-
)}
14+
<script type='application/ld+json'>
15+
{generateBreadcrumbs(breadcrumbs)}
16+
</script>
3517
</Head>
3618
<div className='wrapper'>
3719
<section className='layout'>

helpers/generate-breadcrumbs.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const generateBreadcrumbs = crumbs => {
2+
const BASE_URL = 'https://khendrikse.github.io/';
3+
const crumbsList = [{ name: 'home', item: '' }, ...crumbs];
4+
5+
const json = {
6+
'@context': 'https://schema.org/',
7+
'@type': 'BreadcrumbList',
8+
itemListElement: crumbsList.map(({ name, item }, index) => ({
9+
'@type': 'ListItem',
10+
position: index + 1,
11+
name,
12+
item: `${BASE_URL}${item}`
13+
}))
14+
};
15+
16+
return JSON.stringify(json);
17+
};
18+
19+
export default generateBreadcrumbs;

pages/about.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ProgressiveImage from 'components/ProgressiveImage';
44
import styles from 'styles/about.module.scss';
55

66
const About = ({ title }) => (
7-
<Layout pageTitle={title}>
7+
<Layout pageTitle={title} breadcrumbs={[{ name: 'about', item: 'about/' }]}>
88
<div className='container'>
99
<h2 className='page__title'>About</h2>
1010
<div className={styles.about}>

pages/blog.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Layout from 'components/Layout';
44
import PostList from 'components/PostList';
55

66
const Index = ({ posts, title }) => (
7-
<Layout pageTitle={title}>
7+
<Layout pageTitle={title} breadcrumbs={[{ name: 'blog', item: 'blog/' }]}>
88
<div className='container'>
99
<h2 className='section__title'>Blog</h2>
1010
<PostList posts={posts} />

pages/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import styles from 'styles/home.module.scss';
66
import createFeeds from '../scripts/feed';
77

88
const Index = ({ posts, title }) => (
9-
<Layout pageTitle={title} breadcrumbs={[{ name: 'home', item: '' }]}>
9+
<Layout pageTitle={title}>
1010
<div className='container'>
1111
<div className={styles.home__intro}>
1212
I am a Front-End Developer from The Netherlands with a background in

pages/post/[postname].js

+13-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@ export default function BlogPost({
1313
siteTitle,
1414
frontmatter,
1515
markdownBody,
16-
date
16+
date,
17+
slug
1718
}) {
1819
// eslint-disable-next-line react/jsx-no-useless-fragment
1920
if (!frontmatter) return <></>;
2021

2122
return (
22-
<Layout pageTitle={`${siteTitle} | ${frontmatter.title}`}>
23+
<Layout
24+
pageTitle={`${siteTitle} | ${frontmatter.title}`}
25+
breadcrumbs={[
26+
{ name: 'blog', item: 'blog/' },
27+
{ name: frontmatter.title, item: `post/${slug}` }
28+
]}
29+
>
2330
<article className={styles.post}>
2431
{frontmatter.cover_image ? (
2532
<ProgressiveImage
@@ -79,7 +86,8 @@ BlogPost.propTypes = {
7986
siteTitle: PropTypes.string,
8087
frontmatter: PropTypes.object,
8188
markdownBody: PropTypes.string,
82-
date: PropTypes.array
89+
date: PropTypes.array,
90+
slug: PropTypes.string
8391
};
8492

8593
export async function getStaticProps({ ...ctx }) {
@@ -94,7 +102,8 @@ export async function getStaticProps({ ...ctx }) {
94102
siteTitle: config.title,
95103
frontmatter: data.data,
96104
markdownBody: data.content,
97-
date
105+
date,
106+
slug: postname
98107
}
99108
};
100109
}

pages/projects.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import styles from 'styles/projects.module.scss';
55
import Project from 'components/Project';
66

77
const Projects = ({ title, projects = [] }) => (
8-
<Layout pageTitle={title}>
8+
<Layout pageTitle={title} breadcrumbs={[{ name: 'projects', item: 'projects/' }]}>
99
<div className='container'>
1010
<h2 className='section__title'>Projects</h2>
1111
<div className={styles.projects__card__grid}>

0 commit comments

Comments
 (0)