Using the date from another file

Short version: is it possible to have a page’s last modified date show the last modified date of a datafile that it is build from?

Longer version:

I have a page (call it lecture-materials.md) that is mainly built by a shortcode that accesses a data file. When the data file is updated, the page is recreated.

However: the “last modified” date for the page is the last modified of the markdown of the page, not the data file. The markdown page never gets modified, so the date shows when the site was set up - not when the data was last changed.

You can see this at:

https://pages.graphics.cs.wisc.edu/559-sp22/pages/lecture-materials/

Note how the last modified date is the beginning of the semester, even though things were added recently (to the data file).

Of course, I could do this manually (edit the page markdown each time the data file changes), but I was wondering if there was a more elegant way to do this. Generally, the last modified is correctly updated for everything else (except for the few pages that are mainly created from data).

  1. Is there a way to get a lastmod for a data file? (right now, I use .Page.Lastmod - is there an equivalent .Site.Data.toml_file lastmod check?)

  2. Is there a way to say “this pages last modified date is the later of this file’s date and the data files date?” (given #1, I could do this for display in my footer, but it would be nice if it was used correctly for the “recently changed” widget)

Thanks!

A couple of options…

File modification date/time

{{ (os.Stat "data/foo.json").ModTime }} --> returns a time.Time value

Git commit date/time

template

{{ site.Params.foo }} --> returns a string

build site

export HUGO_PARAMS_FOO=$(git log -1 --format=%cI data/foo.json)
hugo
2 Likes

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