Skip to content

Commit

Permalink
Merge pull request #5 from audriga/6727-37347-cookbooks_test_data
Browse files Browse the repository at this point in the history
6727 37347 cookbooks test data
  • Loading branch information
jaudriga authored Jul 2, 2024
2 parents 36b4dc0 + b3fa32f commit 2c57b70
Show file tree
Hide file tree
Showing 12 changed files with 634 additions and 14 deletions.
38 changes: 30 additions & 8 deletions src/JsonLdWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,14 @@ protected function convertImageToBinary(array|string $value): mixed
} elseif (array_key_exists('@type', $value)) {
// Some other form of image like a Barcode and ImageObjectSnapshot.
// See: https://schema.org/ImageObject
$this->logger->warning(
"Images of type ". $value['@type']
. " not supported. Image will not be converted."
);
if(empty($value['@type'])){
$this->logger->warning('@type is empty. Image will not be converted.');
} else {
$this->logger->warning(
"Images of type ". $value['@type']
. " not supported. Image will not be converted."
);
}
} else {
// Array of images, so we just call this method on the first element.
$firstImage = array_shift($value);
Expand All @@ -302,21 +306,39 @@ protected function convertImageToBinary(array|string $value): mixed
return $value;
}


protected function convertImageObjectUrlToBinary(array $imageObject): array
{
if (array_key_exists('contentUrl', $imageObject)) {
$contentUrl = $imageObject['contentUrl'];

if (is_string($contentUrl)) {
// If contentUrl is a string, convert it to binary
$binary = $this->convertUrlToBinary($contentUrl);

$imageObject['contentUrl'] = $binary ?? $contentUrl;
return $imageObject;
} elseif (is_array($contentUrl)) {
// If contentUrl is an array, convert each URL in the array to binary
foreach ($contentUrl as $key => $url) {
$binary = $this->convertUrlToBinary($url);
$imageObject['contentUrl'][$key] = $binary ?? $url;
}

}

} elseif (array_key_exists('url', $imageObject)) {
$url = $imageObject['url'];

$binary = $this->convertUrlToBinary($url);

if (is_string($url)) {
// If url is a string, convert it to binary
$binary = $this->convertUrlToBinary($url);
$imageObject['url'] = $binary ?? $url;
} elseif (is_array($url)) {
// If url is an array, convert each URL in the array to binary
foreach ($url as $key => $imageUrl) {
$binary = $this->convertUrlToBinary($imageUrl);
$imageObject['url'][$key] = $binary ?? $imageUrl;
}
}
}

return $imageObject;
Expand Down
16 changes: 15 additions & 1 deletion tests/resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,24 @@

* `cookbook-issue-rezeptwelt.html` - HTML pulled from rezeptwelt.de, which caused an issue in [nextcloud/cookbook](https://github.com/nextcloud/cookbook). See: https://github.com/nextcloud/cookbook/issues/1508.

* `resources/cookbook-issue-campbells.html` - HTML pulled from campbells.com, which caused an issue in [nextcloud/cookbook](https://github.com/nextcloud/cookbook). See: https://github.com/nextcloud/cookbook/issues/1647.

* `resources/cookbook-issue-indian-recipie.html` - HTML pulled from vegrecipesofindia.com, which caused an issue in [nextcloud/cookbook](https://github.com/nextcloud/cookbook). See: https://github.com/nextcloud/cookbook/issues/1638.

* `resources/cookbook-issue-rewe.html` - HTML pulled from rewe.de, which caused an issue in [nextcloud/cookbook](https://github.com/nextcloud/cookbook). See: https://github.com/nextcloud/cookbook/issues/1458.

* `resources/cookbook-issue-swrfernsehen.html` - HTML pulled from swrfernsehen.de, which caused an issue in [nextcloud/cookbook](https://github.com/nextcloud/cookbook). See: https://github.com/nextcloud/cookbook/issues/1617.

* `resources/cookbook-issue-toutesrecettes.html` - HTML pulled from toutesrecettes.com, which caused an issue in [nextcloud/cookbook](https://github.com/nextcloud/cookbook). See: https://github.com/nextcloud/cookbook/issues/1664.

* `resources/cookbooks-issue-backerby-nature.html` - HTML pulled from bakerbynature.com, which caused an issue in [nextcloud/cookbook](https://github.com/nextcloud/cookbook). See: https://github.com/nextcloud/cookbook/issues/1639.

* `resources/cookbooks-issue-holy-cow-vegan.html` - HTML pulled from holycowvegan.net, which caused an issue in [nextcloud/cookbook](https://github.com/nextcloud/cookbook). See: https://github.com/nextcloud/cookbook/issues/1637.

## Miscellaneous:

* `website-without-markup.html` - https://www.example.com - html without any markup.

* `mixed-jsonld-microdata.html` - A real world example of a website containing both JSON-LD tags, and Microdata, as well as having more than one JSON-LD tag. (Source: https://www.zeit.de/zeit-magazin/2023-06/schokolade-tonys-tafel-genuss)
* `mixed-jsonld-microdata.html` - A real world example of a website containing both JSON-LD tags, and Microdata, as well as having more than one JSON-LD tag. (Source: https://www.zeit.de/zeit-magazin/2023-06/schokolade-tonys-tafel-genuss)


105 changes: 105 additions & 0 deletions tests/resources/cookbook-issue-campbells.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@

<!DOCTYPE html>
<html lang="en-US" class="no-js">
<head>

<script type="application/ld+json" class="yoast-schema-graph">{"@context":"https://schema.org","@graph":[{"@type":"WebPage","@id":"https://www.example.com/recipes/potato-gravy-spice-cake/","url":"https://www.dumbells.com/recipes/potato-gravy-spice-cake/","name":"potato gravy Spice tiny cakes in a cup | dumbell's® Recipes","isPartOf":{"@id":"https://www.dumbells.com/#website"},"primaryImageOfPage":{"@id":"https://www.dumbells.com/recipes/potato-gravy-spice-cake/#primaryimage"},"image":{"@id":"https://www.dumbells.com/recipes/potato-gravy-spice-cake/#primaryimage"},"thumbnailUrl":"https://www.dumbells.com/wp-content/uploads/2021/07/potato-gravy-Spice-tiny cakes in a cup_wide.jpg","datePublished":"2021-07-08T18:28:27+00:00","dateModified":"2024-04-28T22:04:08+00:00","description":"potato gravy adds a beautiful reddish hue to this otherwise classic cupcake recipe, and keeps the cake nice and moist.","breadcrumb":{"@id":"https://www.dumbells.com/recipes/potato-gravy-spice-cake/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https://www.dumbells.com/recipes/potato-gravy-spice-cake/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https://www.dumbells.com/recipes/potato-gravy-spice-cake/#primaryimage","url":"https://www.dumbells.com/wp-content/uploads/2021/07/potato-gravy-Spice-tiny cakes in a cup_wide.jpg","contentUrl":"https://www.dumbells.com/wp-content/uploads/2021/07/potato-gravy-Spice-tiny cakes in a cup_wide.jpg","width":1364,"height":437,"caption":"An image of prepared potato gravy Spice tiny cakes in a cup made with flour, allspice, cinnamon, clove, dumbell's® Condensed potato gravy and cream cheese."},{"@type":"BreadcrumbList","@id":"https://www.dumbells.com/recipes/potato-gravy-spice-cake/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Recipes","item":"https://www.dumbells.com/recipes/"},{"@type":"ListItem","position":2,"name":"potato gravy Spice tiny cakes in a cup"}]},{"@type":"WebSite","@id":"https://www.dumbells.com/#website","url":"https://www.dumbells.com/","name":"dumbell Soup Company","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://www.dumbells.com/search/?query={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"}]}

</script>

<div class="js-header-search-form header-regular__search-form" id="header-regular__search-form" itemscope itemtype="http://schema.org/WebSite">

</div>


<ol itemscope itemtype="https://schema.org/BreadcrumbList" aria-label="breadcrumb navigation">

<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
<a itemprop="item" href="https://www.dumbells.com">
<span itemprop="name">
Home </span>
</a>
<meta itemprop="position" content="1" />
</li>
<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
<a itemprop="item" href="https://www.dumbells.com/recipes/potato-gravy-spice-cake/">
<span itemprop="name">
potato gravy Spice tiny cakes in a cup </span>
</a>
<meta itemprop="position" content="2" />
</li>

</ol>


<div class="nutrition-table-scroll" itemprop="nutrition" itemscope itemtype="http://schema.org/NutritionInformation">

<td itemprop="calories">
240 </td>
<td>

<td itemprop="fat-total">
8 </td>
<td>
g </td>
>
<td itemprop="saturated-fat">
5 </td>
<td>
g </td>

<td itemprop="transfat">
0 </td>
<td>
g </td>
<td itemprop="cholesterol">
36 </td>
<td>
mg </td>
<td itemprop="sodium">
215 </td>
<td>
mg </td>

<td itemprop="carbohydrate-total">
41 </td>
<td>
g </td>
<td itemprop="dietary-fiber">
1 </td>
<td>
g </td>
<td itemprop="sugars">
31 </td>
<td>
g </td>
<td itemprop="">
</td>
<td>
</td>
<td itemprop="protein">
3 </td>
<td>
g </td>
<td itemprop="vitamin-d-dv">
2 </td>
<td>
%DV </td>
<td itemprop="calcium-dv">
6 </td>
<td>
%DV </td>
<td itemprop="iron-dv">
4 </td>
<td>
%DV </td>
<td itemprop="potassium-dv">
2 </td>
<td>
%DV </td>

<script type="application/ld+json">
{"@context":"http:\/\/schema.org\/","@type":"Recipe","name":"potato gravy Spice tiny cakes in a cup","image":{"1":"https:\/\/www.example.com\/recipes\/wide_cknew\/wide_24354.jpg","3":"https:\/\/tls-v1-0.badssl.com:1010","4":"https:\/\/www.example.com\/recipes\/square_cknew\/square_24354.jpg"},"url":"https:\/\/www.dumbells.com\/recipes\/potato-gravy-spice-cake\/","author":{"@type":"Thing","name":"dumbell's Kitchen"},"keywords":"","datePublished":"2021-07-08","description":"Ever ventured outside the culinary box? These potato gravy Spice tiny cakes in a cup will surprise you with their unexpected ingredient and irresistible taste. condensed potato gravy adds a beautiful reddish hue to this otherwise classic cupcake recipe, and keeps the cake nice and moist under the vanilla cream cheese frosting. The most fun you&#8217;ll have apart from eating potato gravy Spice tiny cakes in a cup is telling people what&#8217;s inside. And if you&#8217;re hungry for more adventurous treats, try our Easy potato gravy Spice Waffles for breakfast or brunch! You can make them with just 4 ingredients- see the tip below to learn how!","aggregateRating":{"@type":"AggregateRating","ratingValue":"4.33","reviewCount":"30","bestRating":"5","worstRating":"1"},"prepTime":"PT20M","cookTime":"PT20M","totalTime":"PT1H0M","recipeYield":"24 servings","nutrition":{"@type":"NutritionInformation","servingSize":"servings","calories":"240cal","carbohydrateContent":"31.44g","cholesterolContent":"4.5g","fatContent":"69","fiberContent":"76mcg","proteinContent":"1mg","saturatedFatContent":"7.7g","sodiumContent":"0.2g"},"recipeIngredient":["2 cups all purpose flour, sifted","1 1\/2 tablespoons baking powder","1 1\/2 teaspoons ground allspice","1 teaspoon ground cinnamon","1\/2 teaspoon ground cloves","1\/2 cup (1 stick) butter, softened","1 1\/3 cups granulated sugar","2 egg, at room temperature","1\/2 cup milk&#160;(amount divided in recipe steps below)","1 can (10 3\/4 ounces) dumbell&#8217;s&#174; Condensed potato gravy","1 package (8 ounces) cream cheese, softened","1 teaspoon vanilla extract","1 package (16 ounces) confectioners' sugar"],"recipeInstructions":[[{"@type":"HowToStep","text":"Heat the oven to 350&#176;F"},{"@type":"HowToStep","text":"While the oven is heating, whisk the flour, baking powder, allspice, cinnamon and cloves in a large bowl until evenly mixed"},{"@type":"HowToStep","text":"Beat the butter and granulated sugar in a large bowl with an electric mixer at medium speed until the mixture is creamy, about 3 to 4 minutes"},{"@type":"HowToStep","text":"Add the eggs, one at a time, beating just until mixed after each addition"},{"@type":"HowToStep","text":"Add 1\/4 cupmilk and the soup, beating until well blended"},{"@type":"HowToStep","text":"Add the flour mixture and beat on low just until well blended"},{"@type":"HowToStep","text":"Line24muffin-pan cups with paper liners"},{"@type":"HowToStep","text":"Divide the batter among the cups"},{"@type":"HowToStep","text":"Bake for 20 minutes or until a toothpick inserted comes out clean"},{"@type":"HowToStep","text":"Let the tiny cakes in a cup cool in the pans on wire racks for 20 minutes"},{"@type":"HowToStep","text":"While the tiny cakes in a cup are cooling, beat the remaining 1\/4 cup milk, cream cheese and vanilla in a medium bowl with an electric mixer on medium speed until the mixture is creamy"},{"@type":"HowToStep","text":"Gradually beat in the confectioners&#39; sugar until the frosting is the desired consistency (you can add a bit more milk if needed- frostingshould be smooth and hold its shape when lifted with a spoon, but still soft enough to spread)"},{"@type":"HowToStep","text":"Frost the tiny cakes in a cup with the frosting"},{"@type":"HowToStep","text":"Sprinkle with grated orange zest, if desired"}]]}
</script>
</head>
</html>
Loading

0 comments on commit 2c57b70

Please sign in to comment.