87 lines
2.0 KiB
TypeScript
87 lines
2.0 KiB
TypeScript
import { INFINITE_SCROLL_GRID_INITIAL } from '@/photo';
|
|
import { getUniqueRecipes } from '@/photo/db/query';
|
|
import { PATH_ROOT } from '@/app/paths';
|
|
import type { Metadata } from 'next';
|
|
import { redirect } from 'next/navigation';
|
|
import { cache } from 'react';
|
|
import { generateMetaForRecipe } from '@/recipe';
|
|
import RecipeOverview from '@/recipe/RecipeOverview';
|
|
import { getPhotosRecipeDataCached } from '@/recipe/data';
|
|
import { staticallyGenerateCategoryIfConfigured } from '@/category/server';
|
|
|
|
const getPhotosRecipeDataCachedCached = cache(getPhotosRecipeDataCached);
|
|
|
|
export const generateStaticParams = staticallyGenerateCategoryIfConfigured(
|
|
'recipes',
|
|
'page',
|
|
getUniqueRecipes,
|
|
recipes => recipes.map(({ recipe }) => ({ recipe })),
|
|
);
|
|
|
|
interface RecipeProps {
|
|
params: Promise<{ recipe: string }>
|
|
}
|
|
|
|
export async function generateMetadata({
|
|
params,
|
|
}: RecipeProps): Promise<Metadata> {
|
|
const { recipe: recipeFromParams } = await params;
|
|
|
|
const recipe = decodeURIComponent(recipeFromParams);
|
|
|
|
const [
|
|
photos,
|
|
{ count, dateRange },
|
|
] = await getPhotosRecipeDataCachedCached({
|
|
recipe,
|
|
limit: INFINITE_SCROLL_GRID_INITIAL,
|
|
});
|
|
|
|
if (photos.length === 0) { return {}; }
|
|
|
|
const {
|
|
url,
|
|
title,
|
|
description,
|
|
images,
|
|
} = generateMetaForRecipe(recipe, photos, count, dateRange);
|
|
|
|
return {
|
|
title,
|
|
openGraph: {
|
|
title,
|
|
description,
|
|
images,
|
|
url,
|
|
},
|
|
twitter: {
|
|
images,
|
|
description,
|
|
card: 'summary_large_image',
|
|
},
|
|
description,
|
|
};
|
|
}
|
|
|
|
export default async function RecipePage({
|
|
params,
|
|
}:RecipeProps) {
|
|
const { recipe: recipeFromParams } = await params;
|
|
|
|
const recipe = decodeURIComponent(recipeFromParams);
|
|
|
|
const [
|
|
photos,
|
|
{ count, dateRange },
|
|
] = await getPhotosRecipeDataCachedCached({
|
|
recipe,
|
|
limit: INFINITE_SCROLL_GRID_INITIAL,
|
|
});
|
|
|
|
if (photos.length === 0) { redirect(PATH_ROOT); }
|
|
|
|
return (
|
|
<RecipeOverview {...{ recipe, photos, count, dateRange }} />
|
|
);
|
|
}
|