Browse Source

Remove empty scraped subrecipes

Tatiana Inama 7 năm trước cách đây
mục cha
commit
7e8a32b8bc
1 tập tin đã thay đổi với 10 bổ sung1 xóa
  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,
+        };
+      }
     )
   )
 }