GuideHow-to recipes

Add last modified time

Show when a page was last changed, from page.date, and set it from the last Git commit of each file in CI.

The frontmatter step sets page.date on every page to the modification time of its source file. A layout can show it as the last update of the page. On a developer's machine that is the time of the last save; in a fresh clone, such as a CI checkout, every file has the time of the checkout, so the site needs the dates from Git instead.

Show the dateLink to this heading

<article>
  {{ content }}
  <footer>
    Last updated:
    <time datetime="{{ page.date | date_to_xmlschema | raw }}">{{ page.date | date: "%B %-d, %Y" }}</time>
  </footer>
</article>
<footer>
  Last updated:
  <time datetime="2025-05-06T07:08:09+00:00">May 6, 2025</time>
</footer>

| raw keeps the + of the offset as it is: the liquid step encodes its output for HTML, which writes + as &#x2B; (valid, but harder to read).

page.date is separate from the front matter date, which is the publication date of a post. A collection is sorted by date when a page has one, else by page.date.

Use the date of the last commitLink to this heading

Set the modification time of every tracked file to the date of its last commit before the build. This script works with GNU touch (Linux) and BSD touch (macOS):

scripts/git-mtime.sh
#!/bin/sh
# Sets the modification time of every file tracked under _content to the date of its last commit.
set -eu
git ls-files -z _content | xargs -0 -n 1 sh -c '
  date=$(TZ=UTC git log -1 --format=%cd --date=format-local:%Y-%m-%dT%H:%M:%SZ -- "$1")
  [ -n "$date" ] && touch -d "$date" "$1"
' sh
chmod +x scripts/git-mtime.sh
./scripts/git-mtime.sh
douze

It runs one git log per file, which takes a few seconds for a thousand files. Files that are not committed yet keep their time.

In GitHub Actions, the checkout must have the history, or every file gets the date of the last commit:

- uses: actions/checkout@v7
  with:
    fetch-depth: 0
- run: ./scripts/git-mtime.sh

Set the date by handLink to this heading

A page can also carry its own date in front matter, under another name, and the layout prefer it:

---
title: Install
updated: 2026-03-01
---
{%- assign updated = updated | default: page.date %}
<time datetime="{{ updated | date_to_xmlschema | raw }}">{{ updated | date: "%B %-d, %Y" }}</time>

See alsoLink to this heading

Esc to close