Add metadata via shortcode

Greetings,

Is it possible to use a short code to affect .Page.params ? I am trying to implement some SEO metadata via schema.org ontologies using the JSON+LD format. However I want to store the metadata which will be loaded into the JSON payload in the body rather than the front matter. In particular, I am looking to describe the videos embedded in a given page. My videos are embedded with a short code. It seems logical that I should keep the metadata I want in the JSON payload with the particular video and put it as an additional element in the shortcode. I am wondering if a shortcode can also insert metadata into the head of the file. It seems that this would be the inverse of what the documentation calls “The .Param Method”

I don’t think there is a conventional way to achieve what you want. That being said, you could search for the shortcode in you page’s .RawContent

{{ with (findRE "{{< youtube id=\"(.|\n)*?\" >}}" .RawContent) }}
  {{ range . }}
    {{ $video := replaceRE "{{< youtube id=\"(.*?)\" >}}" "$1" . }}
    {{ $videos = $videos | append . }}
  {{ end }}
{{ end }}

The code above first look for instances of a youtube shortcode. Then it ranges on the results, and for each occurence, isolate the id argument and add it to a slice.

Then you have a slice with a list of video ids used on that page. Of course you need more than ids, but it give you an approach here.

You could use .Page.Scratch..., from the shortcode. But you need to make sure that you call .Content or similar before you start using that data.

For completenes: When I say similar I mean “the other content related page methods that triggers shortcode rendering”, e.g. .Content, .WordCount…