import { HandlerContext } from "$fresh/server.ts"; import { getDocument, getDocuments } from "@lib/documents.ts"; import { parseRecipe } from "@lib/recipes.ts"; export async function getRecipes() { const documents = await getDocuments(); return Promise.all( documents.filter((d) => { return d.name.startsWith("Recipes/") && d.contentType === "text/markdown" && !d.name.endsWith("index.md"); }).map(async (doc) => { const document = await getDocument(doc.name); const recipe = parseRecipe(document, doc.name); return { ...recipe, id: recipe.id.replace(/^Recipes\//, "").replace(/\.md$/, ""), }; }), ); } export const handler = async ( _req: Request, _ctx: HandlerContext, ): Promise => { const headers = new Headers(); headers.append("Content-Type", "application/json"); const recipes = await getRecipes(); return new Response(JSON.stringify(recipes), { headers }); };