Unable to display the date correctly on a webpage

This issue is related to a hugo site page hosted with GitHub pages.

The following is added in the metadata section of a blog.md file:


title: Blog title
date: 2023-09-10T12:12:25.364Z

The data on the blog page is getting displayed as shown below:

<span title='2023-09-10 12:12:25.364 +0000 UTC'>September 10, 2023</span>

I only want to keep September 10, 2023 and don’t want to include the rest on the blog page.

The html file from where it is fetching the data has the following code:

{{- if not .Date.IsZero -}}
{{- $scratch.Add "meta" (slice (printf "<span title='%s'>%s</span>" (.Date) (.Date | time.Format (default "January 2, 2006" .Site.Params.DateFormat)))) }}
{{- end }}

As part of troubleshooting, I have done several changes in the above code and the print statement, but couldn’t get the desired result. Any inputs or pointers on this will be helpful.

Thank you for your time!

1 Like

Which theme are you using?

The theme is hugo-theme-charlolamode

That theme is out-of-date. Please log an issue with the theme author.

To fix the problem they need to pass the result of the delimit function through the safeHTML function.

For example, change this…

{{- with ($scratch.Get "meta") }}
  {{- delimit . "&nbsp;·&nbsp;" -}}
{{- end -}}

… to this:

{{- with ($scratch.Get "meta") }}
  {{- delimit . "&nbsp;·&nbsp;" | safeHTML -}}
{{- end -}}

They use the delimit function in several places.

2 Likes

Thanks a lot, @jmooring :slight_smile:
This solved the issue.

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