hugo v0.152.2+extended linux/amd64 BuildDate=2025-12-14T00:00:00+00:00 VendorInfo=Fedora:0.152.2-1.fc43
Hi, I have a site where many .md pages will have eg an FAQ section.
I use AI to generate a json-ld version of the FAQ. This is a hard-coded chunk of json-ld that does not need to be changed and does not need to be programmatically created.
I would like to insert this chunk of json-ld into the page. This will be in addition to json-ld that is programmatically created per page based on the page title, etc.
I studied different ways to do this. I might also have eg a How to section in the same page with a separate chunk of json-ld.
I have read that is is ok to have multiple chunks of json-ld in a given page and they can be in head or body or footer. So I have the programmatically created json-ld (based on eg sitename, page title, etc) in head and think it is ok to add chunks of json-ld into the body of the page.
So far I have tried creating a shortcode:
<script type="application/ld+json">
{{ .Inner | safeHTML }}
</script>
And then using the shortcode as eg:
{{< jsonld >}}
{
"@context": "https://schema.org",
"@type": "BlogPosting",
}
{{< /jsonld >}}
The output I get in the source of the page is:
<script type="application/ld+json">"\\n{\\n \\"@context\\": \\"https://schema.org\\",\\n \\"@type\\": \\"BlogPosting\\",\\n}\\n"</script>
Obviously the \n and \ should not be there.
I would also like each item that is on a new line in the shortcode be displayed on a new line in the source of the page.
I have also tried:
<script type="application/ld+json">
{{- .Inner | safeHTML -}}
</script>
But this has the same output.
I have tried to resolve this with 2 different AI’s and they lead me on a never ending recursive try and error path. I have searched for articles on the web and in this forum but all I could find are post discussing programmatic ways of creating json-ld from eg sitename, page title, etc but that is not what I need in this case.
So I am a bit stuck ![]()
Any help would be much appreciated.
Maybe there is a totally different and better way to do this?