Skip to content

Commit 09a6208

Browse files
committed
fix:remove the query param from getStaticProps function and remove filterTag as well
1 parent dae5051 commit 09a6208

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

pages/blog/index.page.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const getCategories = (frontmatter: any): blogCategories[] => {
3535
return Array.isArray(cat) ? cat : [cat];
3636
};
3737

38-
export async function getStaticProps({ query }: { query: any }) {
38+
export async function getStaticProps() {
3939
const files = fs.readdirSync(PATH);
4040
const blogPosts = files
4141
.filter((file) => file.substr(-3) === '.md')
@@ -54,15 +54,12 @@ export async function getStaticProps({ query }: { query: any }) {
5454
});
5555

5656
await generateRssFeed(blogPosts);
57-
58-
const filterTag: string = query?.type || 'All';
59-
6057
return {
6158
props: {
6259
blogPosts,
63-
filterTag,
6460
},
65-
};
61+
};
62+
6663
}
6764

6865
function isValidCategory(category: any): category is blogCategories {
@@ -86,14 +83,16 @@ export default function StaticMarkdownPage({
8683
}) {
8784
const router = useRouter();
8885
// Initialize the filter as an array. If "All" or not specified, we show all posts.
89-
const initialFilters =
90-
filterTag && filterTag !== 'All'
91-
? filterTag.split(',').filter(isValidCategory)
92-
: ['All'];
86+
const initialFilters = router.query.type
87+
? ((router.query.type as string)
88+
.split(',')
89+
.filter(isValidCategory) as blogCategories[])
90+
: ['All'] as blogCategories[];
9391

9492
const [currentFilterTags, setCurrentFilterTags] =
9593
useState<blogCategories[]>(initialFilters);
9694

95+
9796
// When the router query changes, update the filters.
9897
useEffect(() => {
9998
const { query } = router;

0 commit comments

Comments
 (0)