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
198 stars 40 forks source link

Support retrieve first commit timestamp with follow mode #90

Closed blueswen closed 2 years ago

blueswen commented 2 years ago

Add a creation_date_with_follow option to enable retrieve first commit timestamp with follow mode. Since markdown files may be moved for reorganizing MkDocs directory, showing the creation date it actually created would be very useful.

timvink commented 2 years ago

Hi @blueswen! Late reply, as I recently became a father and have been quite busy :)

I really like this addition! Make a lot of sense. I am a bit hesistant to add more options.. I'd like to keep it easy to use for the majority of users.

Do you see any use-case for not using the follow mode by default? We could remove the option, always use follow mode for the creation date, and create a new major release (because the change is not backwards compatible, it might effect existing creation dates).

Do you know if the--follow option is supported by older versions of git also? We don't want to break any builds.

blueswen commented 2 years ago

Congrats 🎊! Family is always first.

The --follow option works fine in most cases. However if add and commit a new file with same content which another old file already in git, the new file will inherent the old file commit log in follow mode. Sine empty is a kind of content, if there is an empty file already in git long time ago, any file add and commit with empty content will be considered be created long time ago too.

# first empty file long time ago
touch a.txt
git add a.txt
git commit -m "01"

# some others commits
echo test > b.txt
git add b.txt
git commit -m "02"

# new empty file
touch c.txt
git add c.txt
git commit -m "03"

# with 01 and 03 commit
git log --follow c.txt

# with 03 commit
git log c.txt

I am not sure how many people would commit an empty file, if not, using the follow mode by default would be great!

After some digging, I found the --follow option was supported since v1.5.3 about 15 years ago. I think maybe it's okay for the majority of users.

timvink commented 2 years ago

Thanks for looking into this.

In the case of new empty files, you would still see a recent revision date, but potentially a much older creation date. An edge case that I'm happy to accept over adding an extra option.

You've also confirmed --follow is not anything new, so it should be well supported by a range of git clients. You also wrote a unit test (kudos) that passed in 12 different environments. Another potential downside of --follow is that it might slightly increase build times, but users looking for speed can already disable creation_date via the options or even use enabled option to switch the plugin on & off depending on the build environment.

So I feel confident we should make follow mode default. Would you be willing to update the PR?

blueswen commented 2 years ago

Making follow mode default is great! I removed the creation_date_with_follow option and modify unit test for follow mode as default. Glad to help!

timvink commented 2 years ago

Just released in v1.1.0 🎉 !

Thanks for the work & the research !