Skip to content

Commit 3a6723b

Browse files
committed
add opengraph image and dynamic metadata
1 parent a1fd258 commit 3a6723b

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

frontend/src/app/jobs/[id]/page.tsx

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,48 @@ import { getJobById } from "@/app/jobs/actions";
44
import { notFound } from "next/navigation";
55
import { Job } from "@/types/job";
66
import JobDetailsWrapper from "@/components/jobs/job-details-wrapper";
7+
import { Metadata } from "next";
8+
import OgImage from "@/assets/OgImage.png";
79

8-
export const metadata = {
9-
title: "Job Details",
10+
type Props = {
11+
params: Promise<{ id: string }>;
12+
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
1013
};
1114

15+
export async function generateMetadata({ params }: Props): Promise<Metadata> {
16+
// Fetch the job
17+
const { id } = await params;
18+
const job: Job | null = await getJobById(id);
19+
20+
// Fallback to parent metadata if job not found
21+
if (!job) {
22+
return {
23+
title: "Job Not Found",
24+
description: "The requested job could not be found.",
25+
};
26+
}
27+
28+
// Create dynamic title and description
29+
const title = `${job.title} at ${job.company.name}`;
30+
const description =
31+
job.one_liner || `${job.title} position at ${job.company.name}`;
32+
33+
return {
34+
title,
35+
description,
36+
openGraph: {
37+
title,
38+
description,
39+
images: [
40+
{
41+
url: OgImage.src,
42+
alt: title,
43+
},
44+
],
45+
},
46+
};
47+
}
48+
1249
type PageProps = {
1350
params: Promise<{ id: string }>;
1451
};

frontend/src/app/layout.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,23 @@ import { Metadata } from "next";
2121
import FeedbackButton from "@/components/ui/feedback-button";
2222
import { Notifications } from "@mantine/notifications";
2323

24+
import OgImage from "../assets/OgImage.png";
25+
2426
export const metadata: Metadata = {
2527
title: {
2628
template: "%s | MAC Jobs Board",
2729
default: "MAC Jobs Board",
2830
},
29-
description: "This is MACs Official Jobs Dashboard.",
31+
openGraph: {
32+
title: "MAC Jobs Board",
33+
description: "Stay ahead with the job board that never sleeps.",
34+
images: [
35+
{
36+
url: OgImage.src,
37+
alt: "MAC Jobs Board",
38+
},
39+
],
40+
},
3041
};
3142

3243
const poppins = Poppins({

frontend/src/assets/OgImage.png

18.3 KB
Loading

0 commit comments

Comments
 (0)