Chobbes / org-chef

A package for making a cookbook and managing recipes with org-mode.
MIT License
327 stars 33 forks source link

Support `HowToSection` and `HowToStep` in json+ld #61

Open egh opened 3 years ago

egh commented 3 years ago

This is a reminder to me to figure out how to do this:

https://blog.themalamarket.com/sichuan-chili-oil-wontons/

Note that this breaks the instructions into multiple groups. Not sure if the internal data structures should be modified to support this.

{
    "@graph": [
        {
            "image": {
                "@id": "https://blog.themalamarket.com/#logo"
            },
            "logo": {
                "caption": "The Mala Market",
                "height": 280,
                "width": 800,
                "url": "https://i2.wp.com/blog.themalamarket.com/wp-content/uploads/2017/03/mala_market_logo_large_dark_bkgd_web-800.jpg?fit=800%2C280&ssl=1",
                "inLanguage": "en-US",
                "@id": "https://blog.themalamarket.com/#logo",
                "@type": "ImageObject"
            },
            "sameAs": [
                "https://www.facebook.com/themalaproject/",
                "https://www.instagram.com/themalaproject/",
                "https://www.pinterest.com/themalaproject/",
                "https://twitter.com/themalaproject"
            ],
            "url": "https://blog.themalamarket.com/",
            "name": "The Mala Market",
            "@id": "https://blog.themalamarket.com/#organization",
            "@type": "Organization"
        },
        {
            "inLanguage": "en-US",
            "potentialAction": [
                {
                    "query-input": "required name=search_term_string",
                    "target": "https://blog.themalamarket.com/?s={search_term_string}",
                    "@type": "SearchAction"
                }
            ],
            "publisher": {
                "@id": "https://blog.themalamarket.com/#organization"
            },
            "description": "",
            "name": "The Mala Market | Inspiration & Ingredients for Sichuan Cooking",
            "url": "https://blog.themalamarket.com/",
            "@id": "https://blog.themalamarket.com/#website",
            "@type": "WebSite"
        },
        {
            "height": 800,
            "width": 1200,
            "url": "https://i1.wp.com/blog.themalamarket.com/wp-content/uploads/2021/04/chaoshou-16.jpg?fit=1200%2C800&ssl=1",
            "inLanguage": "en-US",
            "@id": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#primaryimage",
            "@type": "ImageObject"
        },
        {
            "potentialAction": [
                {
                    "target": [
                        "https://blog.themalamarket.com/sichuan-chili-oil-wontons/"
                    ],
                    "@type": "ReadAction"
                }
            ],
            "inLanguage": "en-US",
            "breadcrumb": {
                "@id": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#breadcrumb"
            },
            "description": "The most authentic Sichuan Chili Oil Wontons (红油抄手, hóngyóu chāoshǒu) on the web! Learn the traditional techniques you never knew were needed",
            "dateModified": "2021-05-19T15:50:45+00:00",
            "datePublished": "2021-05-19T15:42:57+00:00",
            "primaryImageOfPage": {
                "@id": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#primaryimage"
            },
            "isPartOf": {
                "@id": "https://blog.themalamarket.com/#website"
            },
            "name": "Sichuan Chili Oil Wontons (Hongyou Chaoshou, 红油抄手) | The Mala Market",
            "url": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/",
            "@id": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#webpage",
            "@type": "WebPage"
        },
        {
            "itemListElement": [
                {
                    "item": {
                        "name": "Home",
                        "url": "https://blog.themalamarket.com/",
                        "@id": "https://blog.themalamarket.com/",
                        "@type": "WebPage"
                    },
                    "position": 1,
                    "@type": "ListItem"
                },
                {
                    "item": {
                        "name": "Sichuan Chili Oil Wontons (Hongyou Chaoshou, 红油抄手)",
                        "url": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/",
                        "@id": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/",
                        "@type": "WebPage"
                    },
                    "position": 2,
                    "@type": "ListItem"
                }
            ],
            "@id": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#breadcrumb",
            "@type": "BreadcrumbList"
        },
        {
            "potentialAction": [
                {
                    "target": [
                        "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#respond"
                    ],
                    "name": "Comment",
                    "@type": "CommentAction"
                }
            ],
            "inLanguage": "en-US",
            "articleSection": "Meat/Fish",
            "keywords": "chili oil,hua jiao,huajiao,la jiao,light soy sauce,Sichuan pepper,soy sauce",
            "image": {
                "@id": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#primaryimage"
            },
            "publisher": {
                "@id": "https://blog.themalamarket.com/#organization"
            },
            "commentCount": 4,
            "dateModified": "2021-05-19T15:50:45+00:00",
            "datePublished": "2021-05-19T15:42:57+00:00",
            "headline": "Sichuan Chili Oil Wontons (Hongyou Chaoshou, 红油抄手)",
            "author": {
                "@id": "https://blog.themalamarket.com/#/schema/person/9ce8141b542dc21b70cb5d3859738b73"
            },
            "isPartOf": {
                "@id": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#webpage"
            },
            "@id": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#article",
            "@type": "Article"
        },
        {
            "description": "Kathy is a first-gen, twenty-something daughter of two Sichuan immigrants who cooked her way back to her parents’ kitchen during the pandemic and is now helping Ma (you can call her Mala Mama) keep generational family recipes alive. All photos shot and edited by her.",
            "image": {
                "caption": "Kathy Yuan",
                "url": "https://secure.gravatar.com/avatar/9f3b23adf0cb5356b22a57a5350b0eee?s=96&d=identicon&r=g",
                "inLanguage": "en-US",
                "@id": "https://blog.themalamarket.com/#personlogo",
                "@type": "ImageObject"
            },
            "name": "Kathy Yuan",
            "@id": "https://blog.themalamarket.com/#/schema/person/9ce8141b542dc21b70cb5d3859738b73",
            "@type": "Person"
        },
        {
            "mainEntityOfPage": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#webpage",
            "isPartOf": {
                "@id": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#article"
            },
            "@id": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#recipe",
            "recipeInstructions": [
                {
                    "itemListElement": [
                        {
                            "url": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#wprm-recipe-9284-step-0-0",
                            "name": "Smash the ginger and scallion against a cutting board with the flat side of a cleaver. Chop the scallions in half and slice them lengthwise into long slivers. Place in shallow bowl and cover with ¼ cup of cold water for 30 minutes.",
                            "text": "Smash the ginger and scallion against a cutting board with the flat side of a cleaver. Chop the scallions in half and slice them lengthwise into long slivers. Place in shallow bowl and cover with ¼ cup of cold water for 30 minutes.",
                            "@type": "HowToStep"
                        },
                        {
                            "url": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#wprm-recipe-9284-step-0-1",
                            "name": "After soaking, strain the ginger and scallion from the water, squeezing out as much extra juice as possible. Set aside for filling.",
                            "text": "After soaking, strain the ginger and scallion from the water, squeezing out as much extra juice as possible. Set aside for filling.",
                            "@type": "HowToStep"
                        }
                    ],
                    "name": "Congjiang Shui (Scallion Ginger Water)",
                    "@type": "HowToSection"
                },
                {
                    "itemListElement": [
                        {
                            "url": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#wprm-recipe-9284-step-1-0",
                            "name": "Smash garlic to peel and mince roughly. Place in small dipping bowl and add just enough water to cover. Set aside for dressing.",
                            "text": "Smash garlic to peel and mince roughly. Place in small dipping bowl and add just enough water to cover. Set aside for dressing.",
                            "@type": "HowToStep"
                        }
                    ],
                    "name": "Suan Shui (Garlic Water)",
                    "@type": "HowToSection"
                },
                {
                    "itemListElement": [
                        {
                            "url": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#wprm-recipe-9284-step-2-0",
                            "name": "Mince pork if starting from whole pork shoulder (see note). Otherwise, in a medium mixing bowl, add (in order) ground pork, salt, ground white pepper, egg and sesame oil.Start mixing vigorously in one direction. Once egg is entirely incorporated, add 1 tablespoon of the reserved scallion-ginger water. Resume power-stirring, until visible moisture is entirely absorbed, before adding 1 more tablespoon of the water at a time. Repeat as needed. Continue mixing in this way for 10-15 minutes total, all in one direction. At this point, the mixture should look and feel sticky, lighter in color and gummy. Cover and rest in the fridge for 20-30 minutes.",
                            "text": "Mince pork if starting from whole pork shoulder (see note). Otherwise, in a medium mixing bowl, add (in order) ground pork, salt, ground white pepper, egg and sesame oil.Start mixing vigorously in one direction. Once egg is entirely incorporated, add 1 tablespoon of the reserved scallion-ginger water. Resume power-stirring, until visible moisture is entirely absorbed, before adding 1 more tablespoon of the water at a time. Repeat as needed. Continue mixing in this way for 10-15 minutes total, all in one direction. At this point, the mixture should look and feel sticky, lighter in color and gummy. Cover and rest in the fridge for 20-30 minutes.",
                            "@type": "HowToStep"
                        },
                        {
                            "url": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#wprm-recipe-9284-step-2-1",
                            "name": "Set aside a baking sheet or cutting board and a dipping bowl of clean water. Retrieve the meat filling from the fridge. Laying a wrapper in the palm of your nondominant hand like a diamond, add about a ½ teaspoon of filling. Wet the top corner and fold the diamond down into a triangle with the tip pointing toward you. Wet the corner of the side opposite your dominant hand. Squeeze both wings of the triangle between your index and thumb on each hand, then twist them toward the center until the two tips "cross" or overlap. Press and seal. Set aside and repeat until all the filling and wrappers are used up.",
                            "text": "Set aside a baking sheet or cutting board and a dipping bowl of clean water. Retrieve the meat filling from the fridge. Laying a wrapper in the palm of your nondominant hand like a diamond, add about a ½ teaspoon of filling. Wet the top corner and fold the diamond down into a triangle with the tip pointing toward you. Wet the corner of the side opposite your dominant hand. Squeeze both wings of the triangle between your index and thumb on each hand, then twist them toward the center until the two tips "cross" or overlap. Press and seal. Set aside and repeat until all the filling and wrappers are used up.",
                            "@type": "HowToStep"
                        }
                    ],
                    "name": "Folding Chaoshou",
                    "@type": "HowToSection"
                },
                {
                    "itemListElement": [
                        {
                            "url": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#wprm-recipe-9284-step-3-0",
                            "name": "In a wok or large, wide pot, add water two-thirds full and bring to a boil. While waiting for the pot to boil, wash and drain your leafy greens of choice.",
                            "text": "In a wok or large, wide pot, add water two-thirds full and bring to a boil. While waiting for the pot to boil, wash and drain your leafy greens of choice.",
                            "@type": "HowToStep"
                        },
                        {
                            "url": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#wprm-recipe-9284-step-3-1",
                            "name": "In an individual serving bowl, add light soy sauce, salt, sugar, ground huajiao, MSG, chili oil*, lard, garlic water and chopped scallion. Resist the urge to pour more soy sauce, as it easily overpowers the rest of the hongyou flavor. *Skim the red oil from the top of the chili oil jar first, then dredge up solid flakes from the bottom.",
                            "text": "In an individual serving bowl, add light soy sauce, salt, sugar, ground huajiao, MSG, chili oil*, lard, garlic water and chopped scallion. Resist the urge to pour more soy sauce, as it easily overpowers the rest of the hongyou flavor. *Skim the red oil from the top of the chili oil jar first, then dredge up solid flakes from the bottom.",
                            "@type": "HowToStep"
                        },
                        {
                            "url": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#wprm-recipe-9284-step-3-2",
                            "name": "When the pot has reached a rolling boil, add chaoshou (10 = average adult serving). Stir immediately after adding chaoshou to avoid sticking. When the pot comes back to boiling, wait about 40 seconds, then add the reserved cold water. Spoon a small ladleful of broth into the assembled dressing bowls (best described as a "splash" — less is more! Beware that turning this soupy dilutes the hongyou flavor you just created). When the pot returns to a boil and the chaoshou are "rolling" around at the surface, add the drained greens. While they cook briefly, check the chaoshou skin. Remove with a slotted spoon once white edges are cooked through and add to serving bowl. Once bowl is assembled, top with veggies and extra scallions for garnish. Serve immediately and enjoy.",
                            "text": "When the pot has reached a rolling boil, add chaoshou (10 = average adult serving). Stir immediately after adding chaoshou to avoid sticking. When the pot comes back to boiling, wait about 40 seconds, then add the reserved cold water. Spoon a small ladleful of broth into the assembled dressing bowls (best described as a "splash" — less is more! Beware that turning this soupy dilutes the hongyou flavor you just created). When the pot returns to a boil and the chaoshou are "rolling" around at the surface, add the drained greens. While they cook briefly, check the chaoshou skin. Remove with a slotted spoon once white edges are cooked through and add to serving bowl. Once bowl is assembled, top with veggies and extra scallions for garnish. Serve immediately and enjoy.",
                            "@type": "HowToStep"
                        },
                        {
                            "url": "https://blog.themalamarket.com/sichuan-chili-oil-wontons/#wprm-recipe-9284-step-3-3",
                            "name": "Reserve the broth for a clear soup and for washing dishes, soap-free!",
                            "text": "Reserve the broth for a clear soup and for washing dishes, soap-free!",
                            "@type": "HowToStep"
                        }
                    ],
                    "name": "Serving Hongyou Chaoshou For One",
                    "@type": "HowToSection"
                }
            ],
            "recipeIngredient": [
                "1 thumbs rinsed, unpeeled fresh ginger, smashed",
                "2 large scallions, smashed",
                "¼ cup cold water",
                "2-3 cloves garlic, roughly minced",
                "water (just enough to cover)",
                "250 grams ground pork shoulder (approx. 9 ounces) (see note)",
                "½ teaspoon salt (more or less to taste)",
                "⅛ teaspoon ground white pepper (optional)",
                "1  egg",
                "1 teaspoon toasted sesame oil",
                "4 tablespoons scallion-ginger water, divided",
                "1 package wrappers (we use Twin Marquis Shanghai style) (comes in 16-ounce package)",
                "1 small bowl reserved water (for sealing dough)",
                "leafy greens of choice (pea shoots/wan dou jian if available), washed and drained",
                "1 teaspoon Chinese light soy sauce (Zhongba preferred)",
                "2 pinches salt",
                "2 pinches sugar",
                "dash ground huajiao (Sichuan pepper) (see note) (to taste)",
                "pinch MSG (optional)",
                "2 teaspoons oil from chili oil",
                "1 teaspoon flakes from chili oil",
                "½ tablespoon garlic water",
                "½ teaspoon pork lard",
                "1  scallion, finely chopped on diagonal",
                "10  chaoshou",
                "½ cup reserved cold water (for cooking, more if larger pot)",
                "splash hot broth"
            ],
            "recipeYield": [
                "66",
                "66 wontons"
            ],
            "image": [
                "https://blog.themalamarket.com/wp-content/uploads/2021/04/chaoshou-16.jpg",
                "https://blog.themalamarket.com/wp-content/uploads/2021/04/chaoshou-16-500x500.jpg",
                "https://blog.themalamarket.com/wp-content/uploads/2021/04/chaoshou-16-500x375.jpg",
                "https://blog.themalamarket.com/wp-content/uploads/2021/04/chaoshou-16-480x270.jpg"
            ],
            "datePublished": "2021-05-19T10:42:57+00:00",
            "description": "",
            "author": {
                "name": "Kathy Yuan | The Mala Market | Inspiration & Ingredients for Sichuan Cooking",
                "@type": "Person"
            },
            "name": "Sichuan Chili Oil Wontons (Hongyou Chaoshou, 红油抄手)",
            "@type": "Recipe",
            "@context": "http://schema.org/"
        }
    ],
    "@context": "https://schema.org"
}
sixtenbe commented 1 year ago

Was looking at making justOneCookbook work with json-ld and thought it was slightly different than the example given here, until I tried running the code I wrote on the wonton recipe given above.

Primarily wanted to force it into json-ld because I had already modified it on my end to convert html-entites like ' to text. I'll leave my work here for now, might make a couple of pull requests in the future after thinking through some things and possibly asking some question in some other issues.

If I stray from any lisp conventions I'll blame the fact that this is essentially my first foray into lisp or functional languages for that matter.

;; without html-entity conversion and puts section titles as bold text in the first step of the section
(defun org-chef-json-ld-extract-directions (nodes)
  "Get the directions for a recipe from a list of json NODES."
  (cond ((stringp nodes)
         (list nodes))
        ((sequencep nodes)
          ;; flatten needed when HowToSteps are nested inside a HowToSection
          (flatten-tree (mapcar (lambda (n)
                   (cond
                      ((stringp n)
                        n)
                      ;; HowToSection contains itemListElement which is a list with elements of the type HowToStep
                      ((string= (cdr (assq '@type n)) "HowToSection")
                        (let ((sub-steps (cl-coerce (cdr (assq 'itemListElement n)) 'list)))
                        ;; the howtosection name is a bolded prefix to its first step
                        (cl-concatenate 'list (list (format "*%s:* %s"
                                                            (cdr (assq 'name n))
                                                            (cdr (assq 'text (car sub-steps)))))
                                              (org-chef-json-ld-extract-directions (cdr sub-steps)))))
                      (t
                        ;; assume this is a HowToStep
                        (cdr (assq 'text n)))))
                 nodes)))
        (t
          (list "Unknown"))))