import styles from "@/styles/modules/Category.module.scss"; import Link from "next/link"; import { formatTextToUrlName } from "@/utils"; import { Article, Category } from "@prisma/client"; import prisma, { CategoryWithIncludes } from "@/lib/prisma"; import CategoryControl from "../../../components/CategoryControl"; export default function CategoryPage({ category }: { category: CategoryWithIncludes }) { return ( <>

{category?.title}

Most popular articles

{/* {popularArticles?.map((a, i) => { { return ( {a.title} ); } })} */}
{/*

Most recent articles

{recentArticles?.map((a, i) => { { return ( {a.name} ); } })}
*/}

All articles

{category?.articles ? Array.from(category?.articles).map((a: Article, i: number) => { { return ( {a.title} ); } }) : ""}
); } export async function getServerSideProps(context: any) { const categoryName = formatTextToUrlName(context.params.categoryName); let category: CategoryWithIncludes | null = null; await prisma.category .findUnique({ where: { name: categoryName }, include: { articles: true, svg: true }, }) .then( (result: CategoryWithIncludes | null) => { if (result) { category = JSON.parse(JSON.stringify(result)); } }, (reason: any) => { console.log(reason); } ); return { props: { category: category }, // will be passed to the page component as props }; }