Open hwittenborn opened 2 years ago
You can do this today by setting env vars...
Last commit:
To build your site:
source get-last-commit.sh
hugo server
This will show the latest commit. For example:
Author: John Doe
Date: 2022-04-02T09:03:36-07:00
Hash: 3707c2b020903d4fd7c55929c7765f7eadf0d2db
Subject: Update Node.js dependencies
My only problem with that is that it doesn't feel as integrated as the current .GitInfo setup. With that, I don't need to set any environment variables, and I think it'd help if this behaved the same so I don't need to set an environment variables on every build (which could be tedious for contributors to my Hugo sites).
@jmooring commented on Apr 2, 2022
batch-file e.g. set_git_commit_info.bat with content:
@echo off
for /f %%G in ('git rev-parse --short HEAD') do Set HUGOxPARAMSxGITxLAST_COMMITxHASH=%%G
git log -1 --format=%%%an >> out.tmp
for /f "tokens=1 delims=:" %%G in (out.tmp) do set HUGOxPARAMSxGITxLAST_COMMITxAUTHORNAME=%%G
del out.tmp
git log -1 --format=%%%cI >> out.tmp
for /f "tokens=1 delims=:" %%G in (out.tmp) do set HUGOxPARAMSxGITxLAST_COMMITxDATE=%%G
del out.tmp
git log -1 --format=%%%s >> out.tmp
for /f "tokens=1 delims=:" %%G in (out.tmp) do set HUGOxPARAMSxGITxLAST_COMMITxSUBJECT=%%G
del out.tmp
echo. -----------------------------------------------------
echo. hash .....: %HUGOxPARAMSxGITxLAST_COMMITxHASH%
echo. authorname: %HUGOxPARAMSxGITxLAST_COMMITxAUTHORNAME%
echo. date .....: %HUGOxPARAMSxGITxLAST_COMMITxDATE%
echo. subject : %HUGOxPARAMSxGITxLAST_COMMITxSUBJECT%
ouput:
see also : https://ss64.com/nt/for_cmd.html https://teamcity-support.jetbrains.com/hc/en-us/community/posts/4414623708818-Save-output-from-a-command-to-a-temporary-environment-variable
I'd like to have the latest commit in my Git repository at the bottom of my footer that can act as a quick link to the latest change.
Unlike the current system, I don't want this to be specific to a certain page, I just want the latest commit in my current branch to be shown.