Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit 72eee65

Browse files
committed
Display archive data
1 parent 405b83f commit 72eee65

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

pages/posts/[[...slug]].js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,33 @@ const postType = 'post'
1414
* @param {Object} [props] Properties passed to the component.
1515
* @return {Element} Element to render.
1616
*/
17-
export default function BlogPost({post}) {
17+
export default function BlogPost({post, posts, archive}) {
18+
// Check for post archive.
19+
// TODO create generic archive component and move this check to `_app.js`.
20+
if (archive) {
21+
return (
22+
<Layout title="Blog">
23+
<div className="container">
24+
<section>
25+
{!posts || !posts.length ? (
26+
<p>No posts found.</p>
27+
) : (
28+
posts.map((post, index) => (
29+
<>
30+
<article key={index}>
31+
<h1 dangerouslySetInnerHTML={{__html: post?.title}} />
32+
<div dangerouslySetInnerHTML={{__html: post?.excerpt}} />
33+
</article>
34+
<hr />
35+
</>
36+
))
37+
)}
38+
</section>
39+
</div>
40+
</Layout>
41+
)
42+
}
43+
1844
return (
1945
<Layout title={post?.title} description={post?.excerpt}>
2046
<div className="container">
@@ -64,5 +90,7 @@ export async function getStaticProps({params}) {
6490
}
6591

6692
BlogPost.propTypes = {
67-
post: PropTypes.object
93+
post: PropTypes.object,
94+
posts: PropTypes.array,
95+
archive: PropTypes.bool
6896
}

0 commit comments

Comments
 (0)