import { Handlers, PageProps } from "$fresh/server.ts"; import { IngredientsList } from "@islands/IngredientsList.tsx"; import { MainLayout } from "@components/layouts/main.tsx"; import Counter from "@islands/Counter.tsx"; import { Signal, useSignal } from "@preact/signals"; import { Recipe } from "@lib/recipeSchema.ts"; import { RedirectSearchHandler } from "@islands/Search.tsx"; import { KMenu } from "@islands/KMenu.tsx"; import PageHero from "@components/PageHero.tsx"; import { Star } from "@components/Stars.tsx"; import { renderMarkdown } from "@lib/documents.ts"; import { isValidRecipe } from "@lib/recipeSchema.ts"; import { MetaTags } from "@components/MetaTags.tsx"; import { fetchResource } from "@lib/resources.ts"; export const handler: Handlers<{ recipe: Recipe; session: unknown } | null> = { async GET(_, ctx) { try { const recipe = await fetchResource(`recipes/${ctx.params.name}.md`); if (!recipe) { return ctx.renderNotFound(); } return ctx.render({ recipe, session: ctx.state.session }); } catch (_e) { return ctx.renderNotFound(); } }, }; function ValidRecipe({ recipe, amount, portion, }: { recipe: Recipe; amount: Signal; portion: number }) { return ( <>

Ingredients

{portion && }

Preparation

    {recipe.content.recipeInstructions && (recipe.content.recipeInstructions.filter((inst) => !!inst?.length) .map((instruction) => { return (
  1. ); }))}
); } export default function Page( props: PageProps<{ recipe: Recipe; session: Record }>, ) { const { recipe, session } = props.data; const portion = recipe.recipeYield; const amount = useSignal(portion || 1); const subline = [ recipe?.content?.prepTime && `Duration ${recipe?.content?.prepTime}`, ].filter(Boolean) as string[]; return ( ${recipe.content?.name}`} context={recipe} > {session && ( )} {recipe.content.name} {recipe.meta?.rating && }
{isValidRecipe(recipe) ? ( ) : (
{JSON.stringify(recipe)}
)}
); }