16 lines
765 B
JavaScript
16 lines
765 B
JavaScript
import { listIngredientNames } from '#import-recipes/recipes/listIngredientNames.js'
|
|
|
|
// The one file the app reads to feed its suggestions. Its shape is fixed by the
|
|
// app (RECIPE_INDEX_FIXTURE): { generatedAt, recipes: [{ id, name,
|
|
// ingredientNames }] }, so out/index.json can be dropped on the Nextcloud as is.
|
|
// Sorted by name, so the index does not reshuffle just because the source
|
|
// folder was listed in a different order.
|
|
export function buildRecipeIndex({ recipes, generatedAt }) {
|
|
const entries = recipes.map(({ id, document }) => ({
|
|
id,
|
|
name: document.name,
|
|
ingredientNames: listIngredientNames(document)
|
|
}))
|
|
entries.sort((first, second) => first.name.localeCompare(second.name, 'fr'))
|
|
return { generatedAt, recipes: entries }
|
|
}
|