Skip to content

Commit

Permalink
Improve nigella.com
Browse files Browse the repository at this point in the history
  • Loading branch information
reaper47 committed Jul 12, 2024
1 parent ae309ad commit 0b8a25b
Show file tree
Hide file tree
Showing 3 changed files with 1,980 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/scraper/nigella.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,28 @@ func scrapeNigella(root *goquery.Document) (models.RecipeSchema, error) {
if ok {
name = strings.TrimSpace(before)
}
if name == "" {
name = root.Find("h1[itemprop=name]").Text()
}
rs.Name = name

rs.Yield.Value = findYield(root.Find("p[class=serves]").Text())

untrimmedDescription := getPropertyContent(root, "og:description")
description, _ := strings.CutSuffix(untrimmedDescription, "\n\nFor US cup measures, use the toggle at the top of the ingredients list.")
if description == "" {
description = getNameContent(root, "description")
}
rs.Description.Value = description

rs.Image.Value = getPropertyContent(root, "og:image")
if rs.Image.Value == "" {
img := root.Find("img[itemprop=image]").AttrOr("src", "")
if strings.HasPrefix(img, "/assets") {
img = "https://www.nigella.com" + img
}
rs.Image.Value = img
}

rs.Keywords.Values = root.Find("meta[itemprop=keywords]").AttrOr("content", "")

Expand Down
45 changes: 45 additions & 0 deletions internal/scraper/scraper_N_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,51 @@ func TestScraper_N(t *testing.T) {
Video: &models.Videos{},
},
},
{
name: "nigella2.com",
in: "https://www.nigella.com/recipes/guests/coffee-baklava-with-dried-figs",
want: models.RecipeSchema{
AtContext: "https://schema.org",
AtType: &models.SchemaType{Value: "Recipe"},
Category: &models.Category{Value: "uncategorized"},
CookingMethod: &models.CookingMethod{},
Cuisine: &models.Cuisine{},
Description: &models.Description{Value: "The figs give this baklava a natural sweetness, but if you don’t have any, simply replace them with the same amount of extra nuts."},
Keywords: &models.Keywords{
Values: "Birthdays, Christmas, Partytime, Comfort, Fun, Indulgent, Nibbly, Sociable, Sweet, Baking, Guest Recipe,",
},
Image: &models.Image{Value: anUploadedImage.String()},
Ingredients: &models.Ingredients{
Values: []string{
"150 grams shelled pistachios (toasted, plus extra to serve)",
"200 grams walnuts (toasted)", "100 grams soft dried figs (finely chopped)",
"1 teaspoon ground cinnamon", "80 grams caster sugar", "375 grams filo pastry",
"150 grams unsalted butter (melted)",
"2 tablespoons Oasis Greek coffee or other Greek or Turkish finely ground coffee",
"175 grams honey",
"230 grams caster sugar",
},
},
Instructions: &models.Instructions{
Values: []models.HowToItem{
{Text: "For the Greek coffee honey syrup, combine the ingredients and 150 ml (5 fl oz) of water in a small saucepan over high heat. Bring to a simmer, then reduce the heat to medium and cook, stirring occasionally, for 8–10 minutes, until the sugar dissolves. Set aside to cool.", Type: "HowToStep"},
{Text: "Preheat the oven to 180°C (350°F). Grease the base and sides of a 20 cm × 30 cm (8 in × 12 in) baking tin and line with baking paper.", Type: "HowToStep"},
{Text: "Pulse the nuts in a food processor until finely chopped (take care not to overprocess the nuts, otherwise you’ll end up with nut paste). Transfer the nuts to a bowl and stir through the fig, cinnamon and sugar.", Type: "HowToStep"},
{Text: "Carefully lay the filo pastry sheets on a chopping board and trim the sheets to fit the size of the prepared pan or tin. Discard any pastry offcuts. Cover the filo pastry with a clean, slightly damp tea towel, to prevent the sheets from drying out.", Type: "HowToStep"},
{Text: "Brush one filo pastry sheet with butter, then place in the prepared tin. Repeat with another seven sheets of filo pastry, buttering each layer. Scatter over one-third of the nut mixture and top with another four filo sheets, brushing each layer with butter. Repeat this process twice more. Gently press the final filo layer to compress the baklava slightly. Brush generously with the remaining butter.", Type: "HowToStep"},
{Text: "Using a small sharp knife, score the top filo layer into 24 squares. Bake for 25–30 minutes, until the pastry is golden and crispy.", Type: "HowToStep"},
{Text: "Pour the cooled coffee honey syrup over the hot baklava and stand for 1 hour or until the baklava is cool. Using a sharp knife, cut the baklava into pieces along the score marks and serve.", Type: "HowToStep"},
},
},
Name: "Coffee Baklava With Dried Figs",
NutritionSchema: &models.NutritionSchema{},
ThumbnailURL: &models.ThumbnailURL{},
Tools: &models.Tools{Values: []models.HowToItem{}},
Yield: &models.Yield{Value: 24},
URL: "https://www.nigella.com/recipes/guests/coffee-baklava-with-dried-figs",
Video: &models.Videos{},
},
},
{
name: "ninjatestkitchen.eu",
in: "https://ninjatestkitchen.eu/recipe/dirt-worm-brownies",
Expand Down
Loading

0 comments on commit 0b8a25b

Please sign in to comment.