Dates are encoded, but I want raw!

Im trying to output an ISO date format but when I want “2024-11-18T00:00:00+00:00” I keep getting “2024-11-18T00:00:00\u002b00:00”, which I think will be a problem.

Example:

<script type="application/ld+json" data-nkda-type="youtube"  data-nkda-resourceTypes="video">
    {
      "@context": "https://schema.org",
      "@type": "VideoObject",
      "name": "Understanding the Difference: Traditional Management vs. Evidence-Based Management",
      "description": "",
      "thumbnailUrl": [
        "https://i.ytimg.com/vi/3CgKmunwiSQ/maxresdefault.jpg"
       ],
      "uploadDate": "2024-11-18T00:00:00\u002b00:00",
      "duration": "PT0H6M35S",
      "contentUrl": "https://www.youtube.com/3CgKmunwiSQ",
      "embedUrl": "https://www.youtube.com/embed/3CgKmunwiSQ",
    }
    </script>

I’ve tried:

  1. {{ $.Page.Date.Format "2006-01-02T15:04:05-07:00" }}
  2. {{ $.Page.Date.Format “2006-01-02T15:04:05-07:00” | safeHTML }}
  3. {{ $.Page.Date.Format “2006-01-02T15:04:05-07:00” | safeJS }}

Each of these options all result in the same encoded “+”.

Is there a way to get Hugo to output the raw text?

My guess is that you have quotes around the date output like this.

"uploadDate": "{{ $.Page.Date.Format "2006-01-02T15:04:05-07:00" }}",

Remove them and make it look like this:

"uploadDate": {{ $.Page.Date.Format "2006-01-02T15:04:05-07:00" }},

And it should work.

See example here: hugo-theme-zen/layouts/partials/meta_json_ld.html at main · frjo/hugo-theme-zen · GitHub

3 Likes

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