Hugo

Created + last updated date on post (Academic Theme)

In the academic theme, there’s a feature allowing one to set enableGitInfo = true to use the last git commit on a post to display modification times. But at the moment, this seems to be displayed instead of the actual post date.

I don’t 100% understand the syntax, but it looks like the code is here

<span class="article-date">
    {{ $date := $page.Lastmod.Format site.Params.date_format }}
    {{ if eq $page.Type "publication" }}
      {{ $date = $page.Date.Format (site.Params.publications.date_format | default "January, 2006") }}
    {{ else }}
      {{ if ne $page.Params.Lastmod $page.Params.Date }}
          {{ i18n "last_updated" }}
      {{ end }}
    {{ end }}
    <time>{{ $date }}</time>
  </span>
{{ end }}

I’d like to have both the post date and last updated appear, so instead of “Last updated on Jul 20, 2019”, it would be something like “Jul 17, 2019 (last updated Jul 20, 2019).”

(I opened an issue on the repo, but it got closed without comment, so I’m assuming this is not something the developer is interested in implementing).

See the docs on configuring dates and test out which combination you like.

1 Like

On my site, which does not use the Academic theme, I include the following in a layout file to display both the publish date and the last-updated date.

published {{ .Date.Format .Site.Params.dateFormat1 }}
&bull;
updated {{ .Lastmod.Format .Site.Params.dateFormat1 }}

And in my config.yaml file, I have this:

params:
  dateFormat1: 2006-January-2

Config frontmatter settings affect how .Date and .Lastmod are interpreted. Here’s what I use:

frontmatter:
  date: 
    - publishDate
    - :filename
    - date
    - :fileModTime
  publishDate: 
    - publishDate
    - :filename
    - date
    - :fileModTime
  lastmod: 
    - lastmod
    - :fileModTime
    - date
    - publishDate

Hopefully this will help you figure out how to do this in your theme.

–N (gitless and themeless :sunglasses:)

1 Like

Thanks, this is really helpful. I’ll see if I can get this working on academic and report back.