From f6411049d966088c8e429a3460837c0f1d9fa4ab Mon Sep 17 00:00:00 2001 From: Maruf Bepary Date: Thu, 30 Jan 2025 23:01:34 +0000 Subject: [PATCH] Fixing not report being displayed in deployment bby generating static params --- app/projects/[projectKey]/report/page.tsx | 56 ++++++++--------------- 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/app/projects/[projectKey]/report/page.tsx b/app/projects/[projectKey]/report/page.tsx index 57f58af3..52762188 100644 --- a/app/projects/[projectKey]/report/page.tsx +++ b/app/projects/[projectKey]/report/page.tsx @@ -1,13 +1,10 @@ import getMarkdownFromFileSystem from "@/actions/file-system/getMarkdownFromFileSystem"; import SpecialReader from "@/components/Reader/SpecialReader"; import HeadingTwo from "@/components/Text/HeadingTwo"; -import developerName from "@/constants/developerName"; import { PROJECTS_PAGE } from "@/constants/pages"; import projectDatabaseMap from "@/database/Projects/ProjectDatabaseMap"; import ProjectInterface from "@/database/Projects/ProjectInterface"; -import { Metadata, ResolvingMetadata } from "next"; import { notFound } from "next/navigation"; -import React from "react"; // Update the type definitions type Params = { projectKey: string }; @@ -22,13 +19,14 @@ type PageProps = { * @param props Key of the parent project page * @returns Page that displays the report for a project */ -const ModulePage = async ({ params }: PageProps) => { +const ProjectReportPage = async ({ params }: PageProps) => { const resolvedParams = await params; const projectKey: string = resolvedParams.projectKey; const projectData: ProjectInterface = projectDatabaseMap[projectKey]; + const basePath: string = PROJECTS_PAGE.path; const reportBlog: string | undefined = getMarkdownFromFileSystem( - `public${PROJECTS_PAGE.path}/${projectKey}/blog.md` + `public${basePath}/${projectKey}/blog.md` )?.content; const hasBlog: boolean = !!reportBlog; @@ -54,37 +52,23 @@ const ModulePage = async ({ params }: PageProps) => { }; /** - * Generates the metadata for the project report page. - * This includes the title and description of the page. - * This is used for SEO purposes. + * Generates the static paths for the project reports. + * These paths are used to pre-render the report pages. * - * @param props The props for the project report page. - * @param parent The parent metadata that is being resolved. - * @returns The metadata for the project page. - * @see https://nextjs.org/docs/app/building-your-application/optimizing/metadata + * @returns A list of all project keys that have reports for static page generation. */ -export async function generateMetadata( - { params }: { params: Promise }, - parent: ResolvingMetadata -): Promise { - const resolvedParams = await params; - const projectKey: string = resolvedParams.projectKey; - const project: ProjectInterface = projectDatabaseMap[projectKey]; - - if (!project) { - notFound(); - } - - if (!project.archived) { - return { - title: `${developerName} - Project Report: ${project?.name}`, - description: `Report for the project ${project?.name}`, - category: `${PROJECTS_PAGE.label}`, - creator: developerName, - }; - } - - return undefined; -} +export const generateStaticParams = async () => { + return Object.keys(projectDatabaseMap) + .filter((projectKey) => { + // Only include projects that have a blog/report file + const reportExists = getMarkdownFromFileSystem( + `public${PROJECTS_PAGE.path}/${projectKey}/blog.md` + )?.content; + return !!reportExists; + }) + .map((projectKey) => ({ + projectKey, + })); +}; -export default ModulePage; +export default ProjectReportPage;