fix: fetch full history for submodules to fix incorrect last-modified dates#783
fix: fetch full history for submodules to fix incorrect last-modified dates#783Aayushman-nvm wants to merge 3 commits intoprecice:masterfrom
Conversation
|
Still working on it |
|
@MakisH For this issue i might've to modify vendor files... hook.rb to be exact is that fine? |
|
Thanks for the contribution! That's indeed an annoying bug...
Doesn't sound right: |
|
@MakisH haha true but i think u might wanna check this screenshot out: I made a slight change... just a single line change and now the dates are displayed as 14th jan... if u could clarify if 14th jan is ri8 then i think i might've fixed the issue |
|
for a context... I wrote a script (inject_dates.sh) that goes into each submodule, gets the real last-commit date for every markdown file using git, and injects it as last_modified_at into the frontmatter before Jekyll builds. then changed = to ||= in hook.rb so the plugin respects existing frontmatter values instead of always overwriting with its own (broken for submodules) git detection. added two new steps in deploy.yml... one of them is not yet commited |
|
@MakisH here's what ive done so far: inject_dates.sh, a new file im adding to the repo root. This is a shell script that before Jekyll builds, goes into each submodule, finds every markdown file, gets its real last git commit date, and writes it into the file's frontmatter as last_modified_at. .github/workflows/deploy.yml, in this file ive added 3 new steps: unshallow submodules so full git history is available, run inject_dates.sh, and patch the plugin's hook.rb to respect frontmatter instead of overwriting it. The reason I patched patch = to ||= in hook.rb is that the plugin runs git log from the top level git directory, which has no history for files inside submodules so it falls back to filesystem mtime (always today's date). By changing to ||=, the plugin still works as before for all regular pages, but respects the last_modified_at we inject via inject_dates.sh for submodule files where the plugin's git detection fails. Pages that don't have last_modified_at in their frontmatter are completely unaffected. |
|
In case you’re going to test and review this branch locally, you need to run the following scripts in sequence:
bash inject_dates.sh
sed -i 's/item\.data\["last_modified_at"\] = Determinator/item.data["last_modified_at"] ||= Determinator/' \
vendor/bundle/ruby/*/gems/jekyll-last-modified-at-*/lib/jekyll-last-modified-at/hook.rb
bundle exec jekyll serve -lWe don’t need to worry about running these commands manually once the code is merged, they’re already configured in the deploy.yml files. |
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect last-modified dates displayed on website pages sourced from Git submodules. The issue stems from GitHub Actions' actions/checkout performing shallow clones of submodules even when fetch-depth: 0 is specified, resulting in all submodule pages showing the same incorrect date. The fix involves three coordinated changes: unshallowing all submodules after checkout, extracting correct last-commit dates from full Git history and injecting them into YAML frontmatter, and patching the jekyll-last-modified-at gem to respect these frontmatter values instead of computing them from the (incomplete) shallow Git history.
Changes:
- Added a new shell script (
inject_dates.sh) that traverses all submodules, extracts the true last-commit date for each markdown file from Git history, and injects or updates thelast_modified_atfield in YAML frontmatter - Modified the deployment workflow to unshallow submodules, run the date injection script, and patch the jekyll-last-modified-at Ruby gem to respect frontmatter dates
- Implemented a workaround for the actions/checkout shallow clone limitation by combining Git history extraction with runtime gem patching
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| inject_dates.sh | New bash script that extracts last-commit dates from Git history and injects them into YAML frontmatter of markdown files in all submodules |
| .github/workflows/deploy.yml | Adds workflow steps to unshallow submodules, run the date injection script, and patch the jekyll-last-modified-at gem to use frontmatter dates |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0704fac to
4ed2473
Compare
|
Hi, I have some questions:
|
|
Hi @fsimonis : 1:- The workflow already used actions/checkout consistently for all three checkouts. Replacing just the website checkout with a plain git clone while keeping the action for the other two would be inconsistent. As a contributor, I wanted minimal changes to the existing working CI rather than restructuring it. The unshallow step was the least invasive addition to make submodule history available. I'm happy to replace it with a plain deep clone if you prefer. 2:- Even though the history is in git, the plugin architecturally can't reach it. Looking at 3:- My thought was the migration to Hugo will probably take some time and the Jekyll site will remain in production the entire time. Hugo will be developed in a separate branch and only replace Jekyll once it's a complete and tested replica, after which Bootstrap and UI work still follows. Until that point all pages will show wrong dates and users will see that... and for a documentation site that's not great. The project will start in end of May with main coding work beginning in May / June, so users would be seeing wrong dates for several months while the Jekyll site is still live. |


Pages from submodules were showing incorrect last-modified dates because actions/checkout does a shallow clone of submodules even when fetch-depth: 0 is set. This caused all submodule pages to show the same wrong date.
Fix: added a step to unshallow all submodules after checkout so Jekyll can
correctly determine the last commit date for each file.
Closes: Issue #404
Screenshots:

Before -
After -
