Skip to content

Commit

Permalink
Update OG and Twitter images
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchernchong committed Aug 24, 2024
1 parent 8c34452 commit d03d239
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions app/cars/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { type Car, type LatestMonth, RevalidateTags } from "@/types";
import { fetchApi } from "@/utils/fetchApi";
import { formatDateToMonthYear } from "@/utils/formatDateToMonthYear";
import { formatPercent } from "@/utils/formatPercent";
import type { Metadata } from "next";
import type { Metadata, ResolvingMetadata } from "next";
import type { WebPage, WithContext } from "schema-dts";

interface Props {
Expand All @@ -39,9 +39,10 @@ const VEHICLE_TYPE_MAP: Record<string, string> = {
"Sports Utility Vehicle": "SUV",
};

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

if (!month) {
Expand All @@ -51,15 +52,15 @@ export const generateMetadata = async ({

const formattedDate = formatDateToMonthYear(month);
const pageUrl = `/cars`;
const images = `/api/og?title=Car Registrations for ${formattedDate}`;

const previousImages = (await parent).openGraph?.images || [];
// const images = `/api/og?title=Car Registrations for ${formattedDate}`;

return {
title: "Car Registrations",
description: `Breakdown of the cars registered in ${formattedDate} by fuel type and vehicle type`,
openGraph: {
images,
},
twitter: { images },
openGraph: { images: [...previousImages] },
twitter: { images: [...previousImages] },
alternates: {
canonical: pageUrl,
},
Expand Down
Binary file added app/opengraph-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/twitter-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d03d239

Please sign in to comment.