mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-11-18 07:22:06 +00:00
73 lines
1.7 KiB
TypeScript
73 lines
1.7 KiB
TypeScript
import { Metadata } from "next";
|
|
import { unstable_cache } from "next/cache";
|
|
|
|
import { baseUrl } from "@/constants";
|
|
import { collections, dbConnect } from "@/server/mongodb";
|
|
import { Club } from "@/types";
|
|
import { filterClubsByManualEntry } from "@/utils/clubFilters";
|
|
import { errorLog } from "@/utils/logger";
|
|
|
|
import ClubsDisplay from "./ClubsDisplay";
|
|
|
|
export const revalidate = 3600; // Revalidate cache every 6 hours
|
|
|
|
export async function generateMetadata({
|
|
params,
|
|
}: {
|
|
params: Promise<{ locale?: string }>;
|
|
}): Promise<Metadata> {
|
|
const { locale } = await params;
|
|
return {
|
|
alternates: {
|
|
canonical:
|
|
locale === "fr" ? `${baseUrl}/clubs` : `${baseUrl}/${locale}/clubs`,
|
|
languages: {
|
|
fr: `${baseUrl}/clubs`,
|
|
en: `${baseUrl}/en/clubs`,
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
const getClubs = async () => {
|
|
try {
|
|
await dbConnect();
|
|
const data = await collections
|
|
.clubs!.find({ pending: { $ne: true } })
|
|
.sort({ name: 1 })
|
|
.toArray();
|
|
|
|
return filterClubsByManualEntry(data)
|
|
.filter((c) => !!c.coordinates)
|
|
.map<Club>((club) => {
|
|
return {
|
|
id: club._id.toString(),
|
|
name: club.name,
|
|
url: club.url,
|
|
address: club.address,
|
|
email: club.email,
|
|
website: club.website,
|
|
latLng: { lat: club.coordinates[0], lng: club.coordinates[1] },
|
|
};
|
|
});
|
|
} catch (error) {
|
|
errorLog(error);
|
|
throw new Error("Error fetching club data");
|
|
}
|
|
};
|
|
|
|
export default async function Clubs() {
|
|
const clubs = await unstable_cache(
|
|
async () => {
|
|
const data = await getClubs();
|
|
return data;
|
|
},
|
|
["clubs"],
|
|
{
|
|
revalidate: 60 * 60 * 6,
|
|
},
|
|
)();
|
|
|
|
return <ClubsDisplay clubs={clubs} />;
|
|
}
|