Wondering if there is a way to programmatically fill FAQJsonLd,
instead of manual copy+paste.
One thing that comes to my mind is to create custom fields inside the markdown (if you have the option) aside from the HTML/body of the markdown.
You can emulate the question/answer array using something like:
---
title: Some Dummy Title
questionsSection:
- question1:
question: Some question?
answer: Some answer
- question2:
question: Some question 2?
answer: Some answer 2
---
The body of the article
Note: check the structure, maybe you don't need to nest each question/answer inside a new array position (delimited by hyphen, -). I haven't tested the structure, you may need to refine it but get the idea
In this case, you can parse questionsSection for each markdown article and pass it directly to FAQJsonLd component like:
<FAQJsonLd
questions={questionsSection}
/>
As I said, if the structure of questionsSection doesn't fit your specs, you can always flat or flatMap the array.
My idea relies on creating a custom section for each markdown with the FAQs content to avoid parsing the html to find the headings of the posts (which may contain the questions). That markdown section, ideally, should be an array of objects to fit FAQJsonLd specs.
You can even use a JSON notation inside like:
---
title: Some Dummy Title
questionsSection: '{"questions":[{question: "Question 1", answer: "Answer 1"}]}'
---
The body of the article
The idea is exactly the same. Use whatever is more comfortable with you.
FAQJsonLdwith your article content?