.Page.Lastmod always show today's date in deployed site (not the last mod date)

In my single blog page, I have in html: Last updated: {{ .Page.Lastmod.Format "Jan 2, 2006" | safeHTMLAttr }} and this shows on my local machine the correct last modified date of the given blog post.

However, when I deploy my Hugo site to the server (with hugo --cleanDestinationDir --gc --minify) the last modified date for ALL the blog posts shows today’s date (I assume this is a date of deployment).

Why does this happen? How can I show the correct last modified date on my deployed live Hugo site?

  1. Please post your site configuration file.
  2. Please describe how you deploy to your live site.

hello @jmooring ! Here are the details:

pygmentsCodefences: true
pygmentsStyle: vs
baseURL: "https://XXXXXXXX.com"
languageCode: en-us
title: XXXXXXXX
favicon: "images/favicon"
defaultContentLanguage: en
defaultContentLanguageInSubdir: false
enableRobotsTXT: true
enableGitInfo: true
disableLanguages: []
disableKinds: ["RSS"]
summarylength: "2"
permalinks:
  blog: "/:slug/"
  categories: "/category/:slug/"
  tags: "/tags/:slug/"
taxonomies:
  tag: tags
  category: categories
  # author: authors
frontmatter:
  date:
  - date
  - publishDate
  - lastmod
  expiryDate:
  - expiryDate
  lastmod:
  - lastmod
  - :fileModTime
  - :default
  publishDate:
  - date
  - publishDate
languages:
  en:
    weight: 1
    languageCode: en
    contentDir: content/en
    languageName: "English"
    hasCJKLanguage: false
    paginate: 12
  es:
    weight: 2
    languageCode: es
    contentDir: c ontent/es
    languageName: "Español"
    hasCJKLanguage: false
    paginate: 12

## misc
# googleAnalytics: UA-xxx # {{ template "_internal/google_analytics_async.html" . }}

build:
  writeStats: true

Deployment:

  1. I git commit to a master branch on Gitlab
  2. Any commit to master branch will trigger the webhook to send POST https://api.render.com/hooks/gitlab request.
  3. Render server receives the POST request and auto deploys with this build command hugo --cleanDestinationDir --gc --minify to public directory.

You have this:

enableGitInfo: true

and this:

 lastmod:
  - lastmod
  - :fileModTime
  - :default

I think you want something like this:

  lastmod:
  - :git
  - lastmod
  - date
  - publishDate

Or just remove that section because that is the default anyway.

See https://gohugo.io/getting-started/configuration/#configure-dates

Hello @jmooring.
As you can see I already have enableGitInfo: true in my config file.

I tried both options, altering my lastmod section and removing it completely from config file - still the deployed date always shows as today.

I am really confused why it works on my local machine but not when I deploy live.

Did you create your own deployment pipeline, or are you using an existing CI/CD method (e.g., GitHub, GitLab, Netlify)?

Is it looking at a specific directory, or the entire repository?

What does this mean? Git pull, git clone, rsync?

@jmooring apologies for not sharing enough details. I redacted my message earlier and also including more detailed info here:

  1. I git commit to a master branch on Gitlab
  2. Any commit to master branch will trigger the webhook to send POST https://api.render.com/hooks/gitlab request.
  3. Render server receives the POST request and auto deploys with this build command hugo --cleanDestinationDir --gc --minify to public directory.

Earlier I asked you to modify or eliminate the lastmod section of your site configuration file.

  1. If you have multiple configuration files, did you make the change to all of them?
  2. Did you push the changed file(s) to your GitLab repository?
  3. Are you sure the webhook fired?
  4. Are you sure that hugo was run on render.com?
  5. Did you know that cleanDestinationDir does not delete files in public if you don’t have a static directory?

1. If you have multiple configuration files, did you make the change to all of them?
I only have one config.yaml in root of my Hugo site and I applied the changes to it & then tested.

2. Did you push the changed file(s) to your GitLab repository?
Yes, the file is always commited as its part of git repo (its not in .gitignore file).

3. Are you sure the webhook fired?
Yes, I can clearly see in GitLab dashboard the webhooks firing normally. I can also see all the code changes I made on the live site, whether is content or styling/DOM structure.

4. Are you sure that hugo was run on render.com?
Yes, everytime I run git push, after the webook fires, I can see in Render’s dashboard the log output of the console. Here is an example output:

Jun 28 06:36:47 PM  ==> Cloning from https://gitlab.com/__misc/REDACTEDREPO...
Jun 28 06:36:48 PM  ==> Checking out commit XXXXXXXXbdcea5dcXXXXXXX1 in branch master
Jun 28 06:37:02 PM  ==> Downloading cache...
Jun 28 06:37:08 PM  ==> Downloaded 29MB in 3s. Extraction took 1s.
Jun 28 06:37:11 PM  ==> Installing dependencies with Yarn...
Jun 28 06:37:12 PM  yarn install v1.22.10
Jun 28 06:37:12 PM  warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
Jun 28 06:37:12 PM  [1/4] Resolving packages...
Jun 28 06:37:12 PM  [2/4] Fetching packages...
Jun 28 06:37:12 PM  info fsevents@2.3.2: The platform "linux" is incompatible with this module.
Jun 28 06:37:12 PM  info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
Jun 28 06:37:12 PM  [3/4] Linking dependencies...
Jun 28 06:37:14 PM  [4/4] Building fresh packages...
Jun 28 06:37:14 PM  Done in 1.97s.
Jun 28 06:37:24 PM  ==> Using Python version: 3.7.10
Jun 28 06:37:26 PM  ==> Running build command 'hugo --cleanDestinationDir --gc --minify'...
Jun 28 06:37:39 PM  
Jun 28 06:37:39 PM  Total in 12008 ms
Jun 28 06:37:53 PM  ==> Uploading build...

5. Did you know that cleanDestinationDir does not delete files in public if you don’t have a static directory?
I was expecting it will delete any directory that is appointed as the destination. Neverthless, I am 100% sure the code changes are being deployed because every other change I introduce is reflected on the live site.

It sounds like you have configured everything correctly. A couple of thoughts:

  1. Reach out to render.com for assistance.
  2. Share your repository (privately if you wish) so that I can attempt to reproduce the issue.

Related topic:
https://community.render.com/t/1999

@jmooring Yup that’s mine thread and seems like they cant find the reason too. Please allow me to prepare a repo+server so you can have an env to test with same conditions.

1 Like