Skip shortcode in json output

Hello everybody,
for using a search engine I added a second output to my config, which produce a JSON file.

The layout for that JSON has this key/value pairs: "content" $element.Plain, "summary" $element.Summary.

In some of my content markdown files, I uses a custom {{<img>}} shortcode with a caption key. That caption is for a image subtitle.

Now I would like to skip this custom shortcode in the JSON processing, so the caption will not include in the final output.

How can I do that? Is there any filter I can use?

The full JSON layout looks like:

{{- $.Scratch.Add "searchindex" slice -}}
{{- range $index, $element := (where .Site.Pages "Kind" "page") -}}
    {{ $poster := "" }}
    {{ if $element.Params.thumbnail }}
        {{- $image := resources.Get $element.Params.thumbnail -}}
        {{ if $image }}
            {{ $poster = ($image.Fill "220x165 Center").RelPermalink }}
        {{ end }}
    {{ end }}

    {{- $.Scratch.Add "searchindex" (
        dict
            "id" $index
            "title" $element.Title
            "url" $element.RelPermalink
            "tags" $element.Params.tags
            "section" $element.Section
            "content" $element.Plain
            "summary" $element.Summary
            "published" ($element.Date.Format "2. Jan 2006")
            "poster" $poster
            "author" $element.Params.author
    ) -}}
{{- end -}}
{{- $.Scratch.Get "searchindex" | jsonify -}}

I think your best (or only) option would be to create a custom (and empty?) version of that shortcode for that output format, e.g. myshortcode.json.

1 Like

Thank you @bep! That is really the easiest way and exactly what I needed.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.