Skip to content

Commit e1a3786

Browse files
committed
added generateMetaData function in event slug page
1 parent 865bff7 commit e1a3786

File tree

1 file changed

+34
-0
lines changed
  • frontend/src/app/events/[slug]

1 file changed

+34
-0
lines changed

frontend/src/app/events/[slug]/page.js

+34
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,38 @@
11
import { redirect } from "next/navigation";
2+
import { getEvent } from "@/helpers/getEvent";
3+
import { getStrapiMedia } from "@/helpers/strapi_api";
4+
5+
export async function generateMetadata({ params }) {
6+
7+
let slug = params.slug.split('-');
8+
let event_id = slug[slug.length-1];
9+
let event = await getEvent(event_id);
10+
const { title, body, date_time, sigs } = event.attributes
11+
const cover_image = getStrapiMedia(event.attributes.cover_images.data[0]?.attributes.url)
12+
13+
return {
14+
metadataBase: new URL('https://webclub.nitk.ac.in'),
15+
title: title,
16+
description: body.substring(0, 200),
17+
openGraph: {
18+
title: title,
19+
description: body.substring(0, 200),
20+
url: `https://webclub.nitk.ac.in/events/${params.slug}`,
21+
siteName: "WebClub NITK Event",
22+
images: [
23+
{
24+
url: cover_image || 'https://webclub.nitk.ac.in/default-og-image.png',
25+
width: 1200,
26+
height: 630,
27+
alt: title,
28+
},
29+
],
30+
locale: 'en_US',
31+
type: 'article',
32+
publishedTime: date_time,
33+
},
34+
}
35+
}
236

337
export default async function Page({ params }) {
438
redirect(`/events#${params.slug}`);

0 commit comments

Comments
 (0)