Skip to content

Commit 863fcc9

Browse files
committed
add breadcrumbs to post
1 parent c8dc3bf commit 863fcc9

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.breadcrumbs {
2+
span + span {
3+
&:before {
4+
content: '>';
5+
font-size: 12px;
6+
padding: 8px;
7+
}
8+
}
9+
10+
span {
11+
text-transform: capitalize;
12+
font-size: 14px;
13+
}
14+
15+
margin-bottom: 8px;
16+
}

components/Breadcrumbs/index.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import Link from 'next/link';
4+
import styles from './breadcrumbs.module.scss';
5+
6+
const Breadcrumbs = ({ crumbs }) => {
7+
const lastCrumb = crumbs.pop();
8+
9+
return (
10+
<div className={styles.breadcrumbs}>
11+
<span>
12+
<Link href='/'>Home</Link>
13+
</span>
14+
{crumbs.map(crumb => (
15+
<span>
16+
<Link href={crumb.href}>{crumb.name}</Link>
17+
</span>
18+
))}
19+
<span>{lastCrumb.name}</span>
20+
</div>
21+
);
22+
};
23+
24+
Breadcrumbs.propTypes = {
25+
crumbs: PropTypes.arrayOf(
26+
PropTypes.shape({ href: PropTypes.string, name: PropTypes.string })
27+
)
28+
};
29+
30+
export default Breadcrumbs;

pages/post/[postname].js

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Layout from 'components/Layout';
77
import headerColor from 'helpers/post-header';
88
import styles from 'styles/post.module.scss';
99
import ProgressiveImage from 'components/ProgressiveImage';
10+
import Breadcrumbs from 'components/Breadcrumbs';
1011

1112
export default function BlogPost({
1213
siteTitle,
@@ -34,7 +35,13 @@ export default function BlogPost({
3435
)}
3536
<div className='container'>
3637
<div className={styles.post__header__title}>
37-
<h1>{frontmatter.title}</h1>
38+
<Breadcrumbs
39+
crumbs={[
40+
{ name: 'blog', href: '/blog' },
41+
{ name: frontmatter.title }
42+
]}
43+
/>
44+
<h2>{frontmatter.title}</h2>
3845
<div className={styles.post__date_label}>{date}</div>
3946
</div>
4047
</div>

styles/post.module.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
position: relative;
2929
top: -34px;
3030

31-
h1 {
31+
h2 {
3232
margin-top: 0;
33+
font-size: 2em;
3334
}
3435
}
3536
}

0 commit comments

Comments
 (0)