timvink / mkdocs-git-revision-date-localized-plugin

MkDocs plugin to add a last updated date to your site pages
https://timvink.github.io/mkdocs-git-revision-date-localized-plugin/index.html
MIT License
193 stars 39 forks source link

if a file has no git logs, use the last modified timestamp instead of the current #111

Open eshaben opened 1 year ago

eshaben commented 1 year ago

I'm experiencing an interesting issue where I get the following error for a few of the pages of the documentation site I am working on:

WARNING  -  [git-revision-date-localized-plugin] '<file path>' has no git logs, using current timestamp

Then when I view the pages it shows the last modified date correctly, but for the created date, it shows the current date. For example:

Last update:
March 6, 2023
Created:
March 23, 2023

I think if there are no logs found for the created date, it should default to the last update date if available.

It'd also be nice to know the underlying reason why it can't find the git logs for when these pages were created, if you have any ideas?

timvink commented 1 year ago

Hi @eshaben ,

Thanks for reporting. Definitely something wrong here.

The difference between last modified and creation date in commands is only very small:

https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/blob/6150fad41a83abbf7500cf9c75696c5193532305/mkdocs_git_revision_date_localized_plugin/util.py#L122-L124

https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/blob/6150fad41a83abbf7500cf9c75696c5193532305/mkdocs_git_revision_date_localized_plugin/util.py#L132-L134

That translates to:

git log --date=unix --format=%at -n=1 --diff-filter=A <filepath>
git log --date=unix --format=%at -n=1 <filepath>

Could you have a look for one of the pages and run those two commands? I wonder if the first command return something empty or an error..

You're probably not the only one, so keen to figure this one out :)

eshaben commented 1 year ago

Thanks for the response! 🙂

Sure. This is one of the pages we're getting this error on: https://github.com/PureStake/moonbeam-docs/blob/master/builders/build/eth-api/dev-env/scaffold-eth.md

When I run git log --date=unix --format=%at -n 1 --diff-filter=A -- builders/build/eth-api/dev-env/scaffold-eth.md I get 1646250817

Then when I run git log --date=unix --format=%at -n 1 -- builders/build/eth-api/dev-env/scaffold-eth.md I get 1673346506.

karlgo commented 5 months ago

@eshaben - Did you figure out your issue? I'm encountering the same thing, even though I do have git logs for the file in question.

eshaben commented 5 months ago

@karlgo I implemented a workaround. Created a script that checks if the created data is after the last updated date, and, if so, changes the created date to be the same as the last updated. For reference: https://github.com/moonbeam-foundation/moonbeam-docs/blob/master/js/fixCreatedDate.js