Tofu/scripts/import-recipes/recipes/buildRecipeDocument.js
2026-09-18 01:41:02 +02:00

20 lines
991 B
JavaScript

// One recipe file, in schema.org vocabulary. Everything Tofu adds on top of that
// vocabulary is prefixed `tofu:` - the split and the import trace are ours, not
// schema.org's, and the file says so.
//
// recipeIngredient is taken from the raw lines of the aligned split, so the two
// arrays cannot drift apart inside the file: entry i of one is the line of entry
// i of the other, always.
export function buildRecipeDocument({ recipe, parsedIngredients, fileName, importedAt, model }) {
const steps = Array.isArray(recipe.recipeInstructions) ? recipe.recipeInstructions : []
return {
'@context': 'https://schema.org',
'@type': 'Recipe',
name: recipe.name,
recipeYield: recipe.recipeYield ?? null,
recipeIngredient: parsedIngredients.map((ingredient) => ingredient.raw),
recipeInstructions: steps.map((text) => ({ '@type': 'HowToStep', text })),
'tofu:parsedIngredients': parsedIngredients,
'tofu:source': { file: fileName, importedAt, model }
}
}