PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.7
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.7
2.0.13 2.0.12 2.0.11 2.0.10 2.0.9 trunk 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8
blockenberg / blocks / recipe-card / frontend.js

frontend.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.7, at blocks/recipe-card/frontend.js

47 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function () {
2 document.addEventListener('DOMContentLoaded', function () {
3 document.querySelectorAll('.bkrc2-wrap[data-schema="1"]').forEach(function (wrap) {
4 var raw = wrap.dataset.recipe;
5 if (!raw) return;
6 var r;
7 try { r = JSON.parse(raw); } catch(e) { return; }
8
9 var schema = {
10 '@context': 'https://schema.org',
11 '@type': 'Recipe',
12 'name': r.name || '',
13 'description': r.description || '',
14 'prepTime': 'PT' + (r.prepTime || '').replace(/\D+/g,'') + 'M',
15 'cookTime': 'PT' + (r.cookTime || '').replace(/\D+/g,'') + 'M',
16 'totalTime': 'PT' + (r.totalTime || '').replace(/\D+/g,'') + 'M',
17 'recipeYield': r.servings || '',
18 'recipeCuisine': r.cuisine || '',
19 'recipeCategory': r.category || '',
20 'recipeIngredient': r.ingredients || [],
21 'recipeInstructions': (r.steps || []).map(function(s, i) {
22 return { '@type': 'HowToStep', 'text': s, 'position': i + 1 };
23 }),
24 'nutrition': {
25 '@type': 'NutritionInformation',
26 'calories': r.calories ? r.calories + ' calories' : undefined,
27 },
28 'aggregateRating': r.ratingCount ? {
29 '@type': 'AggregateRating',
30 'ratingValue': r.rating || 5,
31 'reviewCount': r.ratingCount,
32 } : undefined,
33 };
34
35 if (r.image) schema.image = r.image;
36
37 // Remove undefined values
38 schema = JSON.parse(JSON.stringify(schema));
39
40 var script = document.createElement('script');
41 script.type = 'application/ld+json';
42 script.textContent = JSON.stringify(schema);
43 document.head.appendChild(script);
44 });
45 });
46 }() );
47