The problem of outputting // statements as \/ in json

  <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "Article",
      "mainEntityOfPage": {
        "@type": "WebPage",
        "@id": "{{ .Permalink }}"
      },
      "headline": "{{ .Title }}",
      "image": "{{ .Params.image.src }}",  
      "author": {
        "@type": "Organization",
        "name": "{{ safeHTML .Site.Params.SiteTitle }}",
        "url": "{{ .Site.BaseURL }}"
      },  
      "publisher": {
        "@type": "Organization",
        "name": "Name",
        "logo": {
          "@type": "ImageObject",
          "url": "{{ .Site.BaseURL }}/img/logo.png"
        }
      },
      "datePublished": "{{ .Params.date }}",
      "dateModified": "{{ .Params.lastmod }}"
    }
    </script>

For some reason the code above is outputting \ / instead of // below, how can I solve this problem?

  <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "Article",
      "mainEntityOfPage": {
        "@type": "WebPage",
        "@id": "http:\/\/localhost:1313\/en\/blog\/merhaba-dunya\/"
      },
      "headline": "Merhaba Dünya!",
      "image": "https:\/\/name.com\/tr\/wp-content\/uploads\/2022\/09\/xss.png",  
      "author": {
        "@type": "Organization",
        "name": "Name",
        "url": "http:\/\/localhost:1313\/"
      },  
      "publisher": {
        "@type": "Organization",
        "name": "Name",
        "logo": {
          "@type": "ImageObject",
          "url": "https://name.com/img/logo.png"
        }
      },
      "datePublished": "2021-04-10 09:19:32 \u002b0100 \u002b0100",
      "dateModified": "2022-01-10 09:19:32 \u002b0100 \u002b0100"
    }
    </script>

Create a map, then convert to JSON.

{{ $m := dict
  "@context" "https://schema.org"
  "@type" "Article"
  "mainEntityOfPage" (dict
    "@type" "WebPage"
    "@id" .Permalink
  )
  "headline" .Title
  "image" .Params.image.src
  "author" (dict
    "@type" "Organization"
    "name" (site.Params.SiteTitle | safeHTML)
    "url" site.BaseURL
  )
  "publisher" (dict
    "@type" "Organization"
    "name" "Name"
    "logo" (dict
      "@type" "ImageObject"
      "url" (print site.BaseURL "/img/logo.png")
    )
  )
  "datePublished" .Params.date
  "dateModified" .Params.lastmod
}}

<script type="application/ld+json">
  {{ jsonify (dict "indent" "  ") $m | safeJS }}
</script>
2 Likes

Thank you very much for your reply. I can solve the problem of the json ones, but there are also non-json ones, how can I do this?

<meta property="og:updated_time" content="{{ .Site.Params.Lastmod }}" />

The output is broken, as you can see:

<meta property="og:updated_time" content="2022-01-10 09:19:32 &#43;0100 &#43;0100" />

<meta property="og:updated_time" {{ printf "content=%q" site.LastChange | safeHTMLAttr}}>
3 Likes

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