Open egh opened 3 years 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"))))
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.