Explorar el Código

Remove empty scraped subrecipes

Tatiana Inama hace 7 años
padre
commit
7e8a32b8bc
Se han modificado 1 ficheros con 10 adiciones y 1 borrados
  1. 10 1
      ktchn/src/recipes/scrape/index.ts

+ 10 - 1
ktchn/src/recipes/scrape/index.ts

@@ -38,7 +38,16 @@ async function scrape(url:string) {
   };
   return RequestPromise(options).then(
     $ => selectSourceAsync(url).then(
-      source => source.scrapeRecipe($)
+      source => {
+        const recipe = source.scrapeRecipe($);
+        const cleanIngredients = recipe.ingredients.filter(subRecipe => {
+          return subRecipe.name !== '' && subRecipe.ingredients.length !== 0;
+        })
+        return {
+          ...recipe,
+          ingredients: cleanIngredients,
+        };
+      }
     )
   )
 }