eleventy-plugin-git-commit-date
v1.0.2
Published
Eleventy plugin to get Git commit time of a file, or a Eleventy collection.
Maintainers
Readme
eleventy-plugin-git-commit-date
This Eleventy plugin provides two template filters:
| Filter | Description |
| :--------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------- |
| getGitCommitDateFromPath | Gets Git commit date from path.Usage: {{ page.inputPath \| getGitCommitDateFromPath }} |
| getCollectionNewestGitCommitDate | Get Git commit date of the newest committed file from a collection.Usage: {{ collections.all \| getCollectionNewestGitCommitDate }} |
🌏 This plugin is made primarily to populate <updated> fields in an RSS feed. Here is a blog post on how to use this plugin with eleventy-plugin-rss.
Usage
1. Install
npm install eleventy-plugin-git-commit-date2. Add to Eleventy config
// eleventy.config.js
import pluginGitCommitDate from "eleventy-plugin-git-commit-date";
export default function (eleventyConfig) {
eleventyConfig.addPlugin(pluginGitCommitDate);
}3. Use in templates
Using {{ page.inputPath | getGitCommitDateFromPath }} will display the git commit date of the file using a local time zone like:
Sun Dec 31 2017 18:00:00 GMT-0600 (Central Standard Time)
Using {{ collections.all | getCollectionNewestGitCommitDate }} will display the git commit date of newest file in the collection using a local time zone like:
Sun Dec 31 2017 18:00:00 GMT-0600 (Central Standard Time)FAQs
When used with GitHub Pages, why are the last commit dates incorrect?
Only the last commit is checked out by GitHub Action Checkout by default. The commit dates for files changed in the previous commits will not be available. You can set the fetch-depth as 0 to get all the history from the Git repository.
- name: Checkout
uses: actions/checkout@v3
+ with:
+ fetch-depth: 0Credits
- @zachleat suggested the use of Git commit dates instead of modified date.
- The core code is based on Jens Oliver Meiert' blog post Eleventy: How to Work Around the “git Last Modified” Performance Bottleneck.
- Pre v1.0 was based on @vuepress/plugin-last-updated.
