import { PageProps } from "fresh"; 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 { 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/markdown.ts"; import { isValidRecipe } from "@lib/recipeSchema.ts"; import { MetaTags } from "@components/MetaTags.tsx"; import { fetchResource } from "@lib/marka/index.ts"; import { RecipeResource } from "@lib/marka/schema.ts"; import { parseIngredients } from "@lib/parseIngredient.ts"; import { parseRating } from "@lib/helpers.ts"; import { HttpError } from "fresh"; import { define } from "../../utils.ts"; export const handler = define.handlers({ async GET(ctx) { try { const recipe = await fetchResource( `recipes/${ctx.params.name}.md`, ); if (!recipe) { throw new HttpError(404); } return { data: { recipe, session: ctx.state.session } }; } catch (_e) { throw new HttpError(404); } }, }); function ValidRecipe({ recipe, amount, portion, }: { recipe: RecipeResource; amount: Signal; portion: number }) { const ingredients = parseIngredients( recipe.content.recipeIngredient?.join("\n") || "", ); return ( <>

Ingredients

{portion && }
{ }

Preparation

    {recipe.content.recipeInstructions && (recipe.content.recipeInstructions .filter((inst) => !!inst?.length) .map((instruction) => { return (
  1. ); }))}
); } export default define.page(function ( props: PageProps<{ recipe: RecipeResource; session: Record }>, ) { const { recipe, session } = props.data; const portion = recipe.content.recipeYield; const amount = useSignal(portion || 1); const subline = [ recipe?.content?.totalTime && `Duration ${recipe?.content?.totalTime}`, ].filter(Boolean) as string[]; const rating = recipe.content.reviewRating?.ratingValue && parseRating(recipe.content.reviewRating.ratingValue); return ( ${recipe.content?.name}`} context={recipe} > {session && ( )} {recipe.content.name} {rating && }
{isValidRecipe(recipe) ? ( ) : (
{recipe}
)}
); });