From 6e994beb5b419198da3a3068f9692510ea2d736b Mon Sep 17 00:00:00 2001 From: Eldemarkki <38920928+Eldemarkki@users.noreply.github.com> Date: Mon, 4 Apr 2022 22:03:09 +0300 Subject: [PATCH] Add thisdelicioushouse.com, fixes #42 --- lib/domain/annoyingDomains.ts | 37 +++++++++++++++++++++++++++++++++++ lib/domain/selectors.ts | 2 ++ 2 files changed, 39 insertions(+) diff --git a/lib/domain/annoyingDomains.ts b/lib/domain/annoyingDomains.ts index 3bf45d9..82b7694 100644 --- a/lib/domain/annoyingDomains.ts +++ b/lib/domain/annoyingDomains.ts @@ -228,6 +228,42 @@ const getChefkochData = (html: string): RecipeMetadata => { } } +const getThisDeliciousHouseData = (html: string): RecipeMetadata => { + const $ = cheerio.load(html); + const title = $('h1.entry-title').text().trim(); + + const ingredients: IngredientsSection[] = $('.wprm-recipe-ingredient-group') + .toArray() + .map(group => { + const g = $(group); + const groupName = g.find('h4').text().trim(); + const rows = g.find("li.wprm-recipe-ingredient").toArray().map(row => { + const r = $(row) + const amount = r.find('span.wprm-recipe-ingredient-amount').text().trim(); + const unit = r.find('span.wprm-recipe-ingredient-unit').text().trim(); + const name = r.find('span.wprm-recipe-ingredient-name').text().trim(); + const note = r.find('span.wprm-recipe-ingredient-notes').text().trim(); + return note ? + `${amount} ${unit} ${name} ${note}`.trim() : + `${amount} ${unit} ${name}`.trim(); + }); + + return { + sectionName: groupName, + ingredients: rows + } + }); + + const directions = $('div.wprm-recipe-instruction-text').toArray().map(element => $(element).text().trim()); + + return { + title, + ingredients, + directions, + domainIsSupported: true, + }; +} + type annoyingDomainToSelectionFunction = { [key in typeof annoyingToParseDomains[number]]: (html: string) => RecipeMetadata } @@ -238,4 +274,5 @@ export const selectionFunctionPerAnnoyingDomain : annoyingDomainToSelectionFunct 'cooking.nytimes.com' : getNYTCookingData, 'tasty.co' : getTastyCoData, 'chefkoch.de' : getChefkochData, + 'thisdelicioushouse.com' : getThisDeliciousHouseData } \ No newline at end of file diff --git a/lib/domain/selectors.ts b/lib/domain/selectors.ts index 688d811..1a04d22 100644 --- a/lib/domain/selectors.ts +++ b/lib/domain/selectors.ts @@ -39,6 +39,7 @@ export const supportedDomains = [ 'thefoodietakesflight.com', 'thepioneerwoman.com', 'thestayathomechef.com', + 'thisdelicioushouse.com', 'valio.fi', 'whatsgabycooking.com', 'yhteishyva.fi' @@ -54,6 +55,7 @@ export const annoyingToParseDomains = [ 'cooking.nytimes.com', 'tasty.co', 'chefkoch.de', + 'thisdelicioushouse.com', ] as const; export const domainIsAnnoyingToParse = (domain: string): boolean => {