|
1 | | -import { notFound } from 'next/navigation'; |
2 | | -import styles from './category.module.css'; |
3 | | -import RecentPosts from '@/components/recentposts/RecentPosts'; |
4 | | -import PopularPosts from '@/components/popularposts/PopularPosts'; |
5 | | -import Pagination from '@/components/pagination/Pagination'; |
6 | | -import Wrapper from '@/components/pagewrapper/Wrapper'; |
7 | | -import Navbar from '@/components/navbar/Navbar'; |
8 | | -import Footer from '@/components/footer/Footer'; |
| 1 | +import React from "react"; // Import useEffect for side effects |
| 2 | +import { notFound } from "next/navigation"; |
| 3 | +import styles from "./category.module.css"; |
| 4 | +import RecentPosts from "@/components/recentposts/RecentPosts"; |
| 5 | +import PopularPosts from "@/components/popularposts/PopularPosts"; |
| 6 | +import Pagination from "@/components/pagination/Pagination"; |
| 7 | +import Wrapper from "@/components/pagewrapper/Wrapper"; |
| 8 | +import Navbar from "@/components/navbar/Navbar"; |
| 9 | +import Footer from "@/components/footer/Footer"; |
9 | 10 |
|
10 | 11 | const validCategories = { |
11 | | - sports: { color: 'green' }, |
12 | | - news: { color: 'red' }, |
13 | | - lifestyle: { color: 'yellow' }, |
14 | | - music: { color: '#CC00FF' }, |
15 | | - movies: { color: 'lightblue' }, |
| 12 | + sports: { color: "green" }, |
| 13 | + news: { color: "red" }, |
| 14 | + lifestyle: { color: "yellow" }, |
| 15 | + music: { color: "#CC00FF" }, |
| 16 | + movies: { color: "lightblue" }, |
16 | 17 | }; |
17 | 18 |
|
18 | 19 | const BlogCategoryLayout = ({ children, params }) => { |
19 | 20 | const { category } = params; |
20 | 21 |
|
21 | | - // Normalize category to lowercase to ensure consistency with validCategories |
22 | 22 | const normalizedCategory = category.toLowerCase(); |
23 | 23 |
|
24 | | - // Check if the category is valid |
25 | 24 | if (!(normalizedCategory in validCategories)) { |
26 | | - return notFound(); // This will render the 404 page |
| 25 | + return notFound(); |
27 | 26 | } |
28 | 27 |
|
29 | 28 | return ( |
30 | 29 | <> |
31 | 30 | <Navbar /> |
32 | 31 | <Wrapper> |
33 | 32 | <div className={styles.container}> |
34 | | - <h1 className={styles.title} style={{'--bg-color':validCategories[normalizedCategory].color}}>{normalizedCategory.charAt(0).toUpperCase() + normalizedCategory.slice(1)} Related Blogs</h1> |
| 33 | + {children} |
| 34 | + <h1 |
| 35 | + className={styles.title} |
| 36 | + style={{ "--bg-color": validCategories[normalizedCategory].color }} |
| 37 | + > |
| 38 | + {normalizedCategory.charAt(0).toUpperCase() + |
| 39 | + normalizedCategory.slice(1)}{" "} |
| 40 | + Related Blogs |
| 41 | + </h1> |
35 | 42 | <div className={styles.content}> |
36 | 43 | <div className={styles.blog}> |
37 | 44 | <RecentPosts className={styles.itemOne} /> |
38 | | - <Pagination width={'100%'} className={styles.button} /> |
| 45 | + <Pagination width={"100%"} className={styles.button} /> |
39 | 46 | </div> |
40 | | - <PopularPosts className={styles.itemTwo} borderRad='20px' marginBlock='5%' isOutline='2px' /> |
| 47 | + <PopularPosts |
| 48 | + className={styles.itemTwo} |
| 49 | + borderRad="20px" |
| 50 | + marginBlock="5%" |
| 51 | + isOutline="2px" |
| 52 | + /> |
41 | 53 | </div> |
42 | 54 | </div> |
43 | 55 | </Wrapper> |
|
0 commit comments