I’m considering moving a WP site to Hugo, but I have a ton of pages with FAQ sections within the content of the page. These sections also generate the FAQ schema: FAQPage - Schema.org Type
In WP this can be done easily. I have a Gutenberg block that provides the HTML structure and then generates the schema.
In Hugo, how would something like this be done in markdown files? I guess I could add the HTML to the markdown, but how would the FAQ schema be generated from that?
Maybe I need to use data files for each FAQ section? Seems like a maintenance headache to me with over 100 FAQ sections. Can data files support markdown content?
Ideally, I’d like to keep the FAQ content within the markdown for that page, but I can’t come up with a way to generate the schema when doing that.
Anyway, I’m not sure how best to go about this. Any advice on how to create structured content within Hugo?
If you have a tool that generates the schema for each content file then it would probably make sense to have it as a Page Resource so that it resides within a Page Bundle and then call it from the templates.
Your question is very broad -as you may have noticed I have linked to several parts of the documentation above- and provide alternative paths you could use to achieve what you want.
Hugo is agnostic and there are no cookie cutter tools, but you most likely can generate what you need on your own with standard Hugo Templates logic.
Probably the best way of doing the above would be to have the questions and answers as front matter parameters in a content file.
Then call these parameters in a Partial, so that you can loop through the questions and answers to generate the faq schema and then also call them through a Shortcode to render them where needed in the body of the content file.
For example in a content file you could define questions & answers and use a shortcode like so:
My primary concern is the need for various elements such as lists and multiple paragraphs in each answer section.
The answers are not typically a simple string of text. They are often a combination of 1-2 dozen HTML tags to make up the complete answer.
I tried looking through the docs, but is standard markdown supported in the front matter? The people writing the content are not very technical, so deviating from standard markdown is probably going to cause issues for us.
Render the schema in the head and also render it at the appropriate place in the body of a page.
Looping through front matter parameters is always simpler.
However from your description perhaps it would be best for non technical writers to write what is required outside Hugo and then have the generated HTML in separate files under a Page Bundes so that these can be called as Page Resources in the templates.
Perhaps others have more ideas about how you could go about generating the faq.
A front matter parameter string can contain HTML or Markdown.
Then you can sanitize the strings as needed with functions like plainify (strip the HTML), safeHTML (render the HTML), markdownify (render the string through the Markdown processor).
I should make clear, this issue goes beyond just FAQ. The same issue goes for other structured data types such as how-to and reviews.
Structured data is a major component of our site and the FAQ example is just a simple example of the overall issue I’m trying to solve.
Structured data is a major part of SEO nowadays, so I’m quite surprised that Hugo doesn’t have a built in way of handling this better.
I’m sure Hugo has a half-dozen ways this could be resolved, but I need to also consider ease of use for writers of the content.
Ideally, a writer should simply write the content in markdown in the order everything should appear on the page - similar to writing a standard text document.
Asking a writer to change their writing method based on the type of content being displayed on the page is a nightmare that I’m trying to avoid.
@divinerites above offered a working example for a simple Schema Setup
But for the complex situation you describe, structured data that is written as complex HTML in the middle of a page’s body and then somehow loop through it to generate the Schema, that is not how things work in Hugo.
The .Content variable that holds the body of a content file is a single variable.
There have been workarounds about splitting .Content in this forum.
However looping through the split Content sections to populate a faq or other schema?
It can probably be done, haven’t really tried, but it probably won’t be clean or easy to achieve.
Ahh, yes, sorry I read about that yesterday but forgot about it. Ok, thanks for the help. I’ll give a few things a shot and see how the team takes it. I have a feeling we’ll have to stick with WP until something a bit more straightforward is available to writers.