TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: Jekyll plugin to access the last Git commit for a file

1 点作者 klandergren超过 2 年前

1 comment

klandergren超过 2 年前
tl; dr: jekyll-last-modified-at, a popular plugin to get the last modified time of a file for a Jekyll site, was causing slow generation times so I wrote a more performant (~70% time reduction for full site regen) alternative at <a href="https:&#x2F;&#x2F;github.com&#x2F;klandergren&#x2F;jekyll-last-commit">https:&#x2F;&#x2F;github.com&#x2F;klandergren&#x2F;jekyll-last-commit</a>, and you get commit info like author, date, and message.<p>I have a 1000+ page Jekyll-based site that was seeing slow generation time—on investigation I discovered the plugin jekyll-last-modified-at was spawning a new process _for every page_ to determine the last modified time (via git commit history). Even after using Jekyll&#x27;s --incremental option—which has its own issues like needing `regenerate: true` in the front matter to regen on data changes—this was still too slow.<p>So to address I did two things:<p>1.) opened two PRs to improve performance, both referenced from this issue and available to try out: <a href="https:&#x2F;&#x2F;github.com&#x2F;gjtorikian&#x2F;jekyll-last-modified-at&#x2F;issues&#x2F;85">https:&#x2F;&#x2F;github.com&#x2F;gjtorikian&#x2F;jekyll-last-modified-at&#x2F;issues...</a>. these were done in the style of the existing codebase and basically just improved caching and switched the git invocation to a single bulk call<p>2.) created a new plugin <a href="https:&#x2F;&#x2F;github.com&#x2F;klandergren&#x2F;jekyll-last-commit">https:&#x2F;&#x2F;github.com&#x2F;klandergren&#x2F;jekyll-last-commit</a> that uses libgit2 (via <a href="https:&#x2F;&#x2F;github.com&#x2F;libgit2&#x2F;rugged">https:&#x2F;&#x2F;github.com&#x2F;libgit2&#x2F;rugged</a>) to interrogate the git repository directly.<p>Implementation details available in both places! Up to you which approach works best for your setup.<p>Notes:<p>* this is only likely relevant to you if a) you want additional commit info beyond date or b) you have a very large Jekyll website (many 100s of pages that each need last modified date); for smaller sites the performance difference will likely be negligible<p>* performance will vary based on how many files you have and how frequently they change throughout the commit history<p>* the original PRs were done in 2021 and the plugin was written in December of 2022 when I wanted to play around with publishing a ruby gem<p>* this was a pretty quick project—if there are issues or errors please report them!