feat: initial refactor to use marka as backend
This commit is contained in:
@@ -3,7 +3,7 @@ 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 { getRecipe, Recipe } from "@lib/resource/recipes.ts";
|
||||
import { Recipe } from "@lib/recipeSchema.ts";
|
||||
import { RedirectSearchHandler } from "@islands/Search.tsx";
|
||||
import { KMenu } from "@islands/KMenu.tsx";
|
||||
import PageHero from "@components/PageHero.tsx";
|
||||
@@ -11,11 +11,12 @@ 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 getRecipe(ctx.params.name);
|
||||
const recipe = await fetchResource(`recipes/${ctx.params.name}.md`);
|
||||
if (!recipe) {
|
||||
return ctx.renderNotFound();
|
||||
}
|
||||
@@ -38,22 +39,24 @@ function ValidRecipe({
|
||||
{portion && <Counter count={amount} />}
|
||||
</div>
|
||||
<IngredientsList
|
||||
ingredients={recipe.ingredients}
|
||||
ingredients={recipe.content.recipeIngredient}
|
||||
amount={amount}
|
||||
portion={portion}
|
||||
/>
|
||||
<h3 class="text-3xl my-5">Preparation</h3>
|
||||
<div class="pl-2">
|
||||
<ol class="list-decimal grid gap-4">
|
||||
{recipe.instructions && (recipe.instructions.map((instruction) => {
|
||||
return (
|
||||
<li
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: renderMarkdown(instruction),
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}))}
|
||||
{recipe.content.recipeInstructions &&
|
||||
(recipe.content.recipeInstructions.filter((inst) => !!inst?.length)
|
||||
.map((instruction) => {
|
||||
return (
|
||||
<li
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: renderMarkdown(instruction),
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}))}
|
||||
</ol>
|
||||
</div>
|
||||
</>
|
||||
@@ -65,35 +68,38 @@ export default function Page(
|
||||
) {
|
||||
const { recipe, session } = props.data;
|
||||
|
||||
const portion = recipe.meta?.portion;
|
||||
const portion = recipe.recipeYield;
|
||||
const amount = useSignal(portion || 1);
|
||||
|
||||
const subline = [
|
||||
recipe?.meta?.time && `Duration ${recipe.meta.time}`,
|
||||
recipe?.content?.prepTime && `Duration ${recipe?.content?.prepTime}`,
|
||||
].filter(Boolean) as string[];
|
||||
|
||||
return (
|
||||
<MainLayout
|
||||
url={props.url}
|
||||
title={`Recipes > ${recipe.name}`}
|
||||
title={`Recipes > ${recipe.content?.name}`}
|
||||
context={recipe}
|
||||
>
|
||||
<RedirectSearchHandler />
|
||||
<KMenu type="main" context={recipe} />
|
||||
<MetaTags resource={recipe} />
|
||||
|
||||
<PageHero image={recipe.meta?.image} thumbnail={recipe.meta?.thumbnail}>
|
||||
<PageHero
|
||||
image={recipe.content?.image}
|
||||
thumbnail={recipe.content?.thumbnail}
|
||||
>
|
||||
<PageHero.Header>
|
||||
<PageHero.BackLink href="/recipes" />
|
||||
{session && (
|
||||
<PageHero.EditLink
|
||||
href={`https://notes.max-richter.dev/Recipes/${recipe.id}`}
|
||||
href={`https://notes.max-richter.dev/resources/recipes/${recipe.name}`}
|
||||
/>
|
||||
)}
|
||||
</PageHero.Header>
|
||||
<PageHero.Footer>
|
||||
<PageHero.Title link={recipe.meta?.link}>
|
||||
{recipe.name}
|
||||
<PageHero.Title link={recipe.content?.link}>
|
||||
{recipe.content.name}
|
||||
</PageHero.Title>
|
||||
<PageHero.Subline
|
||||
entries={subline}
|
||||
@@ -113,12 +119,9 @@ export default function Page(
|
||||
/>
|
||||
)
|
||||
: (
|
||||
<div
|
||||
class="whitespace-break-spaces markdown-body"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: renderMarkdown(recipe?.markdown || ""),
|
||||
}}
|
||||
/>
|
||||
<div class="whitespace-break-spaces markdown-body">
|
||||
{JSON.stringify(recipe)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</MainLayout>
|
||||
|
||||
Reference in New Issue
Block a user