Skip to content

Commit 09de361

Browse files
committed
refactor blog index page and add revalidate property to all getStaticProps
1 parent bd6d3ff commit 09de361

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

pages/blog/category/[tag].js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import BlogPostsContainer from '@/components/blog/BlogPostsContainer';
22
import { paths, tagToHeading } from '@/utils/blogCategories';
33
import { useRouter } from 'next/router';
4+
import { blogRevalidate } from '@/utils/config';
45

56
export default function BlogCategory({ posts }) {
67
const router = useRouter();
@@ -33,6 +34,7 @@ export async function getStaticProps({ params }) {
3334
tagList: post.tag_list,
3435
})),
3536
},
37+
revalidate: blogRevalidate,
3638
};
3739
}
3840

pages/blog/category/all.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import BlogPostsContainer from '@/components/blog/BlogPostsContainer';
2+
import { blogRevalidate } from '@/utils/config';
23

34
export default function BlogCategory({ posts }) {
45
return (
@@ -26,5 +27,6 @@ export async function getStaticProps() {
2627
tagList: post.tag_list,
2728
})),
2829
},
30+
revalidate: blogRevalidate,
2931
};
3032
}

pages/blog/first-post.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

pages/blog/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@ import Container from '@/components/containers/Container';
33
import SearchBar from '@/components/blog/SearchBar';
44
import styles from '@/styles/Blog.module.scss';
55
import Title from '@/components/snippets/Title';
6+
import { blogRevalidate } from '@/utils/config';
7+
import { tagToHeading } from '@/utils/blogCategories';
68

79
export default function Blog({ posts }) {
810
const latestPosts = posts.slice(0, 3);
9-
const nextJsPosts = posts.filter(post => post.tagList.includes('nextjs'));
10-
const typescriptPosts = posts.filter(post =>
11-
post.tagList.includes('typescript')
12-
);
11+
const getPostsByTag = tag => {
12+
return posts.filter(post => post.tagList.includes(tag));
13+
};
1314

1415
return (
1516
<>
1617
<div className={styles.blogSearch}>
1718
<Title customClass='blogTitle' title='Latest Posts' />
18-
{/* <SearchBar /> */}
19+
<SearchBar />
1920
</div>
2021
<BlogPostsContainer posts={latestPosts} />
21-
<BlogPostsContainer posts={nextJsPosts} tag='nextjs' />
22-
<BlogPostsContainer posts={typescriptPosts} tag='typescript' />
22+
{Object.keys(tagToHeading).map(tag => (
23+
<BlogPostsContainer key={tag} posts={getPostsByTag(tag)} tag={tag} />
24+
))}
2325
</>
2426
);
2527
}
@@ -40,5 +42,6 @@ export async function getStaticProps() {
4042
tagList: post.tag_list,
4143
})),
4244
},
45+
revalidate: blogRevalidate,
4346
};
4447
}

utils/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const blogRevalidate = 60 * 60 * 24;

0 commit comments

Comments
 (0)