import styles from "../../../styles/modules/Category.module.scss"; import Link from "next/link"; import { apiUrl } from "../../../global"; import { Article, Category } from "@prisma/client"; import urlJoin from "url-join"; async function GetAllArticles(categoryName: string): Promise { const result: Response = await fetch(urlJoin(apiUrl, `articles?categoryName=${categoryName}`), { cache: "force-cache", next: { revalidate: 3600 }, }); return result.json(); } async function GetPopularArticles(categoryName: string): Promise { const result: Response = await fetch( urlJoin(apiUrl, `articles?categoryName=${categoryName}&limit=6&orderBy=popularity`), { cache: "force-cache", next: { revalidate: 3600 }, } ); return result.json(); } async function GetRecentArticles(categoryName: string): Promise { const result: Response = await fetch( urlJoin(apiUrl, `articles?categoryName=${categoryName}&limit=6&orderBy=recent`), { cache: "force-cache", next: { revalidate: 3600 }, } ); return result.json(); } async function GetCategory(categoryName: string): Promise { const result: Response = await fetch(urlJoin(apiUrl, `categories/name/${categoryName}`), { cache: "force-cache", next: { revalidate: 3600 }, }); return result.json(); } export default async function CategoryPage({ params }: { params: { categoryName: string } }) { const categoryName = params.categoryName.toLowerCase().replaceAll("%20", " "); const category: Category = await GetCategory(categoryName); const allArticles: Article[] = await GetAllArticles(categoryName); const popularArticles: Article[] = await GetPopularArticles(categoryName); const recentArticles: Article[] = await GetRecentArticles(categoryName); 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

{allArticles?.map((a, i) => { { return ( {a.title} ); } })}
); }