61 lines
2.3 KiB
JavaScript
61 lines
2.3 KiB
JavaScript
import UpcomingEventSinglePage from "@/components/events/UpcomingEventSinglePage";
|
|
|
|
export const dynamic = 'force-dynamic';
|
|
export const revalidate = 0;
|
|
|
|
export async function generateStaticParams() {
|
|
try {
|
|
const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:3006/api';
|
|
const res = await fetch(`${API_BASE_URL}/upcoming-events`);
|
|
const data = await res.json();
|
|
if (data && data.success && data.data && data.data.length > 0) {
|
|
const paramsList = [];
|
|
data.data.forEach(event => {
|
|
if (event.slug && String(event.slug).trim()) {
|
|
paramsList.push({ slug: String(event.slug).trim() });
|
|
}
|
|
if (event.id) {
|
|
paramsList.push({ slug: String(event.id) });
|
|
}
|
|
const title = event.title || event.eventtitle || '';
|
|
if (title) {
|
|
const titleSlug = String(title).toLowerCase().trim().replace(/\s+/g, '-').replace(/[^\w\-]+/g, '');
|
|
if (titleSlug) {
|
|
paramsList.push({ slug: titleSlug });
|
|
}
|
|
}
|
|
});
|
|
return paramsList.length > 0 ? paramsList : [{ slug: 'default' }];
|
|
}
|
|
} catch (e) {
|
|
console.error("Error in generateStaticParams:", e);
|
|
}
|
|
return [{ slug: 'default' }];
|
|
}
|
|
|
|
export async function generateMetadata({ params }) {
|
|
try {
|
|
const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:3006/api';
|
|
const res = await fetch(`${API_BASE_URL}/upcoming-events/slug/${params.slug}`);
|
|
const data = await res.json();
|
|
if (data && data.success && data.data) {
|
|
const event = data.data;
|
|
return {
|
|
title: `${event.title || event.eventtitle} | Tamil Culture Waterloo`,
|
|
description: event.description || event.eventdescription || `Details for ${event.title || event.eventtitle}.`,
|
|
};
|
|
}
|
|
} catch (e) {
|
|
console.error("Error in generateMetadata:", e);
|
|
}
|
|
|
|
return {
|
|
title: "Upcoming Event | Tamil Culture Waterloo",
|
|
};
|
|
}
|
|
|
|
export default function Page({ params }) {
|
|
return <UpcomingEventSinglePage slug={params.slug} />;
|
|
}
|
|
|