Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG FIX: Project report not displayed on Vercel #479

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 20 additions & 36 deletions app/projects/[projectKey]/report/page.tsx
Original file line number Diff line number Diff line change
@@ -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 };
Expand All @@ -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;
Expand All @@ -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<Params> },
parent: ResolvingMetadata
): Promise<Metadata | undefined> {
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;