Accessing current date via shortcode?

I have a site built using Zola (loving it, so far!) and have a “last updated” section in my footer. Currently, I’m manually updating that date, but it would be great if there was a shortcode I could use to get the current date (as of the zola build time). I looked through the docs, but didn’t see anything about dates and times. Did I just miss something?

Otherwise, would anyone have some tips about how to implement such a feature?

Do you want that updated for the entire site or one markdown page

  1. A single entry (page) does have the ability for an ‘updated’ and ‘date’ field.
    Sections and Pages | Zola

  2. In the pagination section one can sort by date and updated
    Section | Zola
    Presumably if you use updated then the top page will have the most recent date.
    Note: Any page that is missing the data it needs to be sorted will be ignored and won't be rendered. For example, if a page is missing the date variable and its section sets sort_by = “date” , then that page will be ignored. The terminal will warn you if this occurs.

  3. And one can add any field to the entire site via the config.toml file by adding

[extra]
updated = “”

However, Imho i do believe that date must be manually entered. and does not use the build time.

Thanks for those suggestions. This feels like something that could be a useful short code, but I don’t know enough about the internals of Zola to know how to do that.

Either way, I was able to get what I needed by adding the date to the extra section metadata, and then writing a small sed script that will replace the date with the current one that gets run as a pre-commit hook on my repo. Thanks for the help!

Example script:

#!/bin/bash
# put this file in <repo_dir>/.git/hooks/pre-commit and make it executable
# it will be run every time you make a commit to silently update the date
# in the _index.md file at commit time (only on the main branch)

BRANCH_NAME=$( git rev-parse --abbrev-ref HEAD )
if [ "$BRANCH_NAME" = "main" ]; then
    echo "------------------------------------------------------------"
    echo "Pre-commit hook to update \"last updated\" date on main page"
    echo "------------------------------------------------------------"

    TODAY=$(date +%Y-%m-%d)
    echo "Original updated date in content/_index.md:"
    echo $( grep updated\ = content/_index.md )
    echo ""

    sed -i -E "s/^updated = \"[0-9]{4}-[0-9]{2}-[0-9]{2}\"$/updated = \"${TODAY}\"/" content/_index.md

    echo "Updated updated date in content/_index.md:"
    echo $( grep updated\ = content/_index.md )
    echo ""

    git add content/_index.md
fi

So this is a git commit time less than a post time - and doesn’t alter the individual posts data but section. Yeah thats cool actually. I think its good to have a site update time.

make with zola is useful. And rsync it up to aws.