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
206 stars 44 forks source link

Add {{git_creation_date_localized}} #50

Closed PegasisForever closed 3 years ago

PegasisForever commented 3 years ago

relating issue: #49

This pr adds {{git_creation_date_localized}}

I improved performance of getting the creation date by using git.log(realpath, date="short", format="%at", diff_filter="A"). The reverse option mentioned in the issue doesn't work because it reverse the output after limiting the lines.

PegasisForever commented 3 years ago

When I run tests (using pytest), a lot of them fails even without my changes. Any ideas?

mkdocs version 1.1.2

image

timvink commented 3 years ago

When I run tests (using pytest), a lot of them fails even without my changes. Any ideas?

I created a fresh python 3.9 env, I'm using same mkdocs version. Tests succeed on master branch, but fail on PegasisForever:git_creation_date_localized branch with same error.

The error suggests it probably has to do with this line:

https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/pull/50/files#diff-00b1f736d69bb089d8eafceeb52bc04b19ebecf339a8b33ccc3404a21ebd32cbR158

PegasisForever commented 3 years ago

I fixed the tests and added a new one to test creation dates.

timvink commented 3 years ago

Really nice work! Thanks for the PR!

My only doubt is if we can remove enable_creation_date as a parameter, and make it available by default. I will also do some work on the documentation.

Plan to release this later this week!

timvink commented 3 years ago

I was going through the existing code base and cleaning things up a bit. The trick of using diff_filter="A" is that it only selects the commit that created the file, correct?

commit_timestamp = git.log(
                    realpath, date="short", format="%at", diff_filter="A"
                )
timvink commented 3 years ago

OK, I opened https://github.com/squidfunk/mkdocs-material/issues/2551 to discuss adding native support for the creation date in the material theme.

PegasisForever commented 3 years ago

My only doubt is if we can remove enable_creation_date as a parameter

The reason I didn't enable enable_creation_date as default is I don't want to change the behaviour of old websites.

The trick of using diff_filter="A" is that it only selects the commit that created the file, correct?

Yes, see https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203

timvink commented 3 years ago

The reason I didn't enable enable_creation_date as default is I don't want to change the behaviour of old websites.

Yes, it's the right decision. My doubt was 1) what is you only want to have the creation date, and not the last updated? and 2) what we if add more git date related fields. It's a fine solution for now.

FYI, I also opened this PR for native mkdocs-material support: https://github.com/squidfunk/mkdocs-material/pull/2579