2023-07-26 13:47:01 +02:00
|
|
|
import { HandlerContext } from "$fresh/server.ts";
|
2023-07-27 15:28:50 +02:00
|
|
|
import { getDocument } from "@lib/documents.ts";
|
|
|
|
import { parseRecipe } from "@lib/recipes.ts";
|
2023-07-26 13:47:01 +02:00
|
|
|
|
|
|
|
export async function getRecipe(name: string) {
|
|
|
|
const document = await getDocument(`Recipes/${name}.md`);
|
|
|
|
|
|
|
|
const recipe = parseRecipe(document, name);
|
|
|
|
|
|
|
|
return recipe;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const handler = async (
|
|
|
|
_req: Request,
|
|
|
|
_ctx: HandlerContext,
|
|
|
|
): Promise<Response> => {
|
|
|
|
const recipe = await getRecipe(_ctx.params.name);
|
|
|
|
|
|
|
|
const headers = new Headers();
|
|
|
|
headers.append("Content-Type", "application/json");
|
|
|
|
|
|
|
|
return new Response(JSON.stringify(recipe));
|
|
|
|
};
|