Skip to content

Instantly share code, notes, and snippets.

@BluePraise
Created October 26, 2024 21:05
Show Gist options
  • Select an option

  • Save BluePraise/c4e4897c47a11e1ed8aa8a935defa7f4 to your computer and use it in GitHub Desktop.

Select an option

Save BluePraise/c4e4897c47a11e1ed8aa8a935defa7f4 to your computer and use it in GitHub Desktop.
Shortcode to show last git commit in 11ty post/page
const childProcess = require('child_process');
// Add this to .eleventy.js file
eleventyConfig.addShortcode('lastCommitDate', function () {
const lastUpdatedFromGit = childProcess.execSync(`git log -1 --format=%cd --date=short`).toString().trim();
const formattedDate = DateTime.fromISO(lastUpdatedFromGit).toLocaleString(DateTime.DATETIME_HUGE);
return formattedDate;
});
// reference post: magaliechetrit.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment