Skip to content

Commit

Permalink
Fix undefined month in metadata
Browse files Browse the repository at this point in the history
Relates to #67
  • Loading branch information
ruchernchong committed Aug 17, 2024
1 parent 248cb7e commit 9b2952d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/cars/[type]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,30 @@ import { API_URL, EXCLUSION_LIST, SITE_URL } from "@/config";
import { Car, LatestMonth } from "@/types";
import { capitaliseWords } from "@/utils/capitaliseWords";
import { fetchApi } from "@/utils/fetchApi";
import { formatDateToMonthYear } from "@/utils/formatDateToMonthYear";

interface Props {
params: { type: string };
searchParams: { [key: string]: string | string[] | undefined };
searchParams?: { [key: string]: string };
}

export const generateMetadata = async ({
params,
searchParams,
}: Props): Promise<Metadata> => {
const { type } = params;
const month = searchParams?.month;
let month = searchParams?.month;

if (!month) {
const latestMonth = await fetchApi<LatestMonth>(`${API_URL}/months/latest`);
month = latestMonth.cars;
}

const images = `${SITE_URL}/api/og?type=${type}&month=${month}`;

return {
title: capitaliseWords(type),
description: `Car registration for ${type} fuel type in Singapore for the month of ${month}.`,
description: `Car registration for ${type} fuel type in Singapore for the month of ${formatDateToMonthYear(month)}.`,
openGraph: { images },
twitter: { images },
alternates: {
Expand Down

0 comments on commit 9b2952d

Please sign in to comment.