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
208 stars 45 forks source link

Feature request: exclude specific commits when calculating the 'last update' calculation #113

Open markszabo opened 1 year ago

markszabo commented 1 year ago

In our usage it sometimes happens that we need to make changes to many/all markdown files at once, e.g. running a formatter, or when the name of an internal product or team changes. We would like to exclude these changes from the 'last update' calculation, as they don't mean that the content was actually checked and actualized (but merely that someone run a search and replace over the entire repo). This doesn't happen that often, so we have a limited number of these commits (less than 5).

Thus I'd like to propose a new config option called exclude_commits as a list of commit ids that should not be considered when calculating the last update time, e.g.

plugins:
  - git-revision-date-localized:
      exclude_commits:
          - 6150fad
          - 7d89e01
          - e7f82de

If this sounds like something you would accept to be part of the plugin, I'm happy to send a PR with the implementation and doc update.

timvink commented 1 year ago

That would be a nice addition. I'd prefer to this outside of the plugin if possible.

For example, for git-authors the main command it git blame, and there you have the option to specify a file with commit hashes to ignore (see https://github.com/timvink/mkdocs-git-authors-plugin/issues/71) for details.

Preferably I would like a similar approach for this plugin (which uses git log, see below). A quick glance at the docs for git log show this isn't possible.

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

Do you already have a specific approach in mind?

timvink commented 1 year ago

The --exclude parameter (https://git-scm.com/docs/git-log#Documentation/git-log.txt---excludeltglob-patterngt) seems promising

Going through this blogpost, it seems we could add a .git-log-exclude to the root of a project, container a list of commit hashes.

Update: from the blogpost, it also requires setting a global or local git config option (something like git config log.exclude .git-log-exclude). That's something to be aware of when collaborating with a team on documentation, or when setting up your CI/CD build.

If that works, we would only need to update the documentation with an additional 'how to' page.

markszabo commented 1 year ago

Thanks for the quick reply! I played around with the options (including the one you suggested), but didn't find anything that would work. The closest I could get is to exclude certain commits by commit message, but even this requires cli parameters and doesn't seem to be configurable via the git config:

git log --oneline --invert-grep --grep='Update team name' docs/index.md

Meanwhile my colleague implemented this feature and will send a PR after testing it.