Переглянути джерело

Fix joy of baking ingredients bug

Tatiana Inama 7 роки тому
батько
коміт
9d510eb332
1 змінених файлів з 4 додано та 4 видалено
  1. 4 4
      ktchn/src/recipes/scrape/sources/joy-of-baking.ts

+ 4 - 4
ktchn/src/recipes/scrape/sources/joy-of-baking.ts

@@ -16,14 +16,14 @@ function getRecipeName($: CheerioSelector): string {
 }
 
 function getIngredients($: CheerioSelector): ComposedIngredients[] {
-  const rawData = $('td [width="249"] p').toArray();
+  const rawData = $('td [width="252"] p').toArray();
   const isIngredient = (element: CheerioElement): boolean => $(element).hasClass('ingredient');
-
-  let ingredients: ComposedIngredients[] = [];
+  let ingredients: ComposedIngredients[] = [{name: '', ingredients: []}];
   return rawData.reduce((list:any, element, index) => {
     let rawIngredient = $(element).text();
     rawIngredient = rmBreakLines(rawIngredient);
-    let last = list.length - 1;
+    let last = list.length ? list.length - 1 : 0;
+
     if(isIngredient(element)) {
       let ingredient = parseIngredients(rawIngredient);
       list[last].ingredients = list[last].ingredients.concat([{