Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure domains' alphabetical ordering with ESLint rules #39

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/domain/annoyingDomains.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { combineIngredientNamesAndAmounts, getItemListFromSelector, getTitleFromSelector, IngredientsSection, RecipeMetadata } from "../recipes";
import cheerio from 'cheerio';
import { annoyingToParseDomains } from "./selectors";

interface JoyFoodSunshineIngredientArray {
ingredients: [{
Expand Down Expand Up @@ -229,13 +228,15 @@ const getChefkochData = (html: string): RecipeMetadata => {
}

type annoyingDomainToSelectionFunction = {
[key in typeof annoyingToParseDomains[number]]: (html: string) => RecipeMetadata
[domain: string]: (html: string) => RecipeMetadata
}

// minKeys is 5 to "filter out" other cases in this file. It's kind of hacky...
/* eslint sort-keys: ["error", "asc", { minKeys: 5 }] */
export const selectionFunctionPerAnnoyingDomain : annoyingDomainToSelectionFunction = {
'bonappetit.com' : getBonAppetitData,
'joyfoodsunshine.com' : getJoyFoodSunshineData,
'chefkoch.de' : getChefkochData,
'cooking.nytimes.com' : getNYTCookingData,
'joyfoodsunshine.com' : getJoyFoodSunshineData,
'tasty.co' : getTastyCoData,
'chefkoch.de' : getChefkochData,
}
91 changes: 24 additions & 67 deletions lib/domain/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,4 @@
export const supportedDomains = [
'allrecipes.com',
'bbcgoodfood.com',
'bettycrocker.com',
'blueberry.org',
'bonappetit.com',
'budgetbytes.com',
'chefkoch.de',
'cookingclassy.com',
'cooking.nytimes.com',
'christinascucina.com',
'delish.com',
// 'eatwell101.com',
'epicurious.com',
'food.com',
'foodnetwork.com',
'gimmesomeoven.com',
'howtobbqright.com',
'ice.edu',
'inspiredtaste.net',
'joyfoodsunshine.com',
'justonecookbook.com',
'kingarthurbaking.com',
'kitchenstories.com',
'kotikokki.net',
'littlesweetbaker.com',
'loveandlemons.com',
'myrecipes.com',
'natashaskitchen.com',
'onceuponachef.com',
'pillsbury.com',
'pinchofyum.com',
'reseptitaivas.fi',
'sallysbakingaddiction.com',
'simplyrecipes.com',
'spendwithpennies.com',
'tasteofhome.com',
'tasty.co',
'thefoodietakesflight.com',
'thepioneerwoman.com',
'thestayathomechef.com',
'valio.fi',
'whatsgabycooking.com',
'yhteishyva.fi'
] as const;

export const domainIsSupported = (domain: string): boolean => {
return supportedDomains.find((d) => d === domain) !== undefined
}

export const annoyingToParseDomains = [
'bonappetit.com',
'joyfoodsunshine.com',
'cooking.nytimes.com',
'tasty.co',
'chefkoch.de',
] as const;

export const domainIsAnnoyingToParse = (domain: string): boolean => {
return annoyingToParseDomains.find((d) => d === domain) !== undefined
}
import { selectionFunctionPerAnnoyingDomain } from './annoyingDomains';

type recipeSelectorSet = {
titleSelector: string,
Expand All @@ -67,8 +7,11 @@ type recipeSelectorSet = {
directionsSelector: string,
}

type domainInformationSelector = { [key in typeof supportedDomains[number]]?: recipeSelectorSet };
type domainInformationSelector = { [domain: string]: recipeSelectorSet };

// minKeys is 5 to "ignore" the titleSelector, ingredientsSelector and directionsSelector keys.
// If recipeSelectorSet has more keys later, minKeys should be increased to `key count + 1`
/* eslint sort-keys: ["error", "asc", { minKeys: 5 }] */
export const recipeSelectors: domainInformationSelector = {
'allrecipes.com' : {
titleSelector: 'div[class="headline-wrapper"] > h1',
Expand All @@ -95,16 +38,16 @@ export const recipeSelectors: domainInformationSelector = {
ingredientsSelector: 'ul[class="wprm-recipe-ingredients"] > li',
directionsSelector: 'ul[class="wprm-recipe-instructions"] > li',
},
'cookingclassy.com' : {
titleSelector: 'h1[class="title"]',
ingredientsSelector: 'ul[class="wprm-recipe-ingredients"] > li',
directionsSelector: 'ul[class="wprm-recipe-instructions"] > li',
},
'christinascucina.com' : {
titleSelector: 'h2.mv-create-title',
ingredientsSelector: 'div.mv-create-ingredients > ul > li',
directionsSelector: 'div.mv-create-instructions li, div.mv-create-instructions *:header:not(*[class~="mv-create-instructions-title"])'
},
'cookingclassy.com' : {
titleSelector: 'h1[class="title"]',
ingredientsSelector: 'ul[class="wprm-recipe-ingredients"] > li',
directionsSelector: 'ul[class="wprm-recipe-instructions"] > li',
},
'delish.com' : {
titleSelector: 'h1[class="content-hed recipe-hed"]',
ingredientsSelector: 'div[class="ingredient-lists"] > div[class="ingredient-item"] > span[class="ingredient-description"] > p',
Expand Down Expand Up @@ -274,6 +217,20 @@ export const recipeSelectors: domainInformationSelector = {
}
}

export const annoyingToParseDomains = Object.keys(selectionFunctionPerAnnoyingDomain);
export const supportedDomains = [
...Object.keys(recipeSelectors),
...annoyingToParseDomains
];

export const domainIsSupported = (domain: string): boolean => {
return supportedDomains.find((d) => d === domain) !== undefined
}

export const domainIsAnnoyingToParse = (domain: string): boolean => {
return annoyingToParseDomains.find((d) => d === domain) !== undefined
}

// Wishlist
// Weird 'deselect all' https://www.foodnetwork.com/recipes/alton-brown/cocoa-brownies-recipe-2085484
// cafedelites.com
Expand Down