Giter VIP home page Giter VIP logo

eleventy-plugin-git-commit-date's Introduction

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.

โš ๏ธ Getting Git commit date is a bit slow (~50ms for each path). So, use it sparingly. It's recommended to call this filter within a production flag.

Usage

1. Install

npm install eleventy-plugin-git-commit-date

2. Add to Eleventy config

// .eleventy.js

const pluginGitCommitDate = require("eleventy-plugin-git-commit-date");

module.exports = 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: 0

Credits

eleventy-plugin-git-commit-date's People

Contributors

saneef avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

trebledj

eleventy-plugin-git-commit-date's Issues

Wrong Commit Date on GitHub Pages

This is solved, just posting this for posterity and in case others have the same issue.

When testing locally, the plugin works fine. But when deploying to GitHub pages, you may find that the commit date fetched is wrong (all happen to be the time of the build).

The issue lies with repository checkout. By default, actions/checkout won't checkout the entire repository, meaning git log can't find the right commit. You can fix this by increasing the fetch depth of actions/checkout.

      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 10000

For large repositories, I suppose it will slow down the build. Not sure if there's a better way to alleviate this.

Perhaps it would also be beneficial to highlight this issue in the README, in case new users also encounter it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.