Skip to main content

Actions Status PyPI - Python Version PyPI PyPI - Downloads codecov GitHub contributors PyPI - License

mkdocs-git-revision-date-localized-plugin

MkDocs plugin that enables displaying the date of the last git modification of a page. The plugin uses babel and timeago.js to provide different localized date formats. Initial fork from mkdocs-git-revision-date-plugin.

demo

(Example when used together with the mkdocs-material theme)

Setup

Install the plugin using pip3 with the following command:

pip3 install mkdocs-git-revision-date-localized-plugin

Next, add the following lines to your mkdocs.yml:

plugins:
  - search
  - git-revision-date-localized

If you have no plugins entry in your config file yet, you'll likely also want to add the search plugin. MkDocs enables it by default if there is no plugins entry set.

Note when using build environments

This plugin needs access to the last commit that touched a specific file to be able to retrieve the date. By default many build environments only retrieve the last commit, which means you might need to:

Change your CI settings
  • github actions: set fetch_depth to 0 (docs)
  • gitlab runners: set GIT_DEPTH to 1000 (docs)
  • bitbucket pipelines: set clone: depth: full (docs)

Usage

In supported themes

In markdown pages

In your markdown files you can use the {{ git_revision_date_localized }} tag anywhere you'd like:

Last update: {{ git_revision_date_localized }}

Extending existing themes

You can customize an existing theme by overriding blocks or partials and using the page.meta.git_revision_date_localized tag.

To add a revision date to the default mkdocs theme by adding a overrides/partials folder to your docs folder and updating your mkdocs.yml file:

theme:
    name: mkdocs
    custom_dir: docs/overrides

And then adding a new file docs/overrides/content.html with the following content:

content.html
<!-- Overwrites content.html base mkdocs theme, taken from 
https://github.com/mkdocs/mkdocs/blob/master/mkdocs/themes/mkdocs/content.html -->

{% if page.meta.source %}
    <div class="source-links">
    {% for filename in page.meta.source %}
        <span class="label label-primary">{{ filename }}</span>
    {% endfor %}
    </div>
{% endif %}

{{ page.content }}

{% if page.meta.git_revision_date_localized %}
    <small>Last update: {{ page.meta.git_revision_date_localized }}</small>
{% endif %}

 

In custom themes

When writing your own custom themes you can use the page.meta.git_revision_date_localized jinja tag:

{% if page.meta.git_revision_date_localized %}
  Last update: {{ page.meta.git_revision_date_localized }}
{% endif %}

You can style the output using CSS: the date outputs are always wrapped in <span class='git-revision-date-localized-plugin git-revision-date-localized-plugin-{type}></span> (where {type} is replaced with the type option set in the plugin).

Options

You can customize the plugin by setting options in mkdocs.yml. For example:

plugins:
  - git-revision-date-localized:
      type: timeago
      time_zone: Europe/Amsterdam
      locale: en
      fallback_to_build_date: false

type

Default is date. To change the date format, set the type parameter to one of date, datetime, iso_date, iso_datetime or timeago. Example outputs:

28 November, 2019           # type: date (default)
28 November, 2019 13:57:28  # type: datetime
2019-11-28                  # type: iso_date
2019-11-28 13:57:26         # type: iso_datetime
20 hours ago                # type: timeago

time_zone

Default is UTC. Specify a time zone database name (reference). This option is especially relevant when using type: datetime and type: iso_datetime. Note that when using timeago (with type: timeago) any difference in time zones between server and client will be handled automatically.

locale

Default is None. Specify a two letter ISO639 language code to display dates in your preferred language.

  • When not set, this plugin will look for locale or language options set in your theme. If also not set, the fallback is English (en)
  • When used in combination with type: date or type: datetime, translation is done using babel which supports these locales
  • When used in combination with type: timeago then timeago.js is added to your website, which supports these locales. If you specify a locale not supported by timeago.js, the fallback is English (en)

fallback_to_build_date

Default is false. If set to true the plugin will use the time at mkdocs build instead of the file's last git revision date when git is not available. This means the revision date can be incorrect, but this can be acceptable if you want your project to also successfully build in environments with no access to GIT.

Contributing

Contributions are very welcome! Please read CONTRIBUTING.md before putting in any work.

Metadata

Release files for mkdocs-git-revision-date-localized-plugin 0.7.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mkdocs-git-revision-date-localized-plugin 0.7.4
File Size Uploaded
mkdocs-git-revision-date-localized-plugin-0.7.4.tar.gz 20.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mkdocs-git-revision-date-localized-plugin 0.7.4
File Interpreter ABI Platform
mkdocs_git_revision_date_localized_plugin-0.7.4-py3-none-any.whl Python 3 none any Details

Total release size: 39.9 kB

Release files / mkdocs-git-revision-date-localized-plugin-0.7.4.tar.gz

Download URL mkdocs-git-revision-date-localized-plugin-0.7.4.tar.gz
Size 20.2 kB
Tags Source
SHA-256 checksum
How to use checksums
cc708d8efe8e1e220c530fcaf0ad17e227a5842b943b60cb6e1de8462c93c23c
BLAKE2b-256 checksum
How to use checksums
548a1bed334896ab31e655d5b851ee02feceb9d25d4c96de6a42ff0ec27562c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.0

Release files / mkdocs_git_revision_date_localized_plugin-0.7.4-py3-none-any.whl

Download URL mkdocs_git_revision_date_localized_plugin-0.7.4-py3-none-any.whl
Size 19.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e40f2b4e8bf8a9b31d98ebf648186bf92f369516194eeb7db33d2b028d51d44d
BLAKE2b-256 checksum
How to use checksums
a525409e5dd5ee5fbcea996dc0b2b518710416cab83a68696979d2cef3763377
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.0

Release history Release notifications | RSS feed

1.6.0

2 release files

1.5.4

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.7

2 release files

1.4.6

2 release files

1.4.5

2 release files

1.4.4

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.9

2 release files

1.2.8

2 release files

1.2.7

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.12

2 release files

0.11.1

2 release files

0.11

2 release files

0.10.3

2 release files

0.10.2

2 release files

0.10.0

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9

2 release files

0.8

2 release files

This release

0.7.4 This release

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7

2 release files

0.6

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.8

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4

2 release files

0.3.3

2 release files

0.3.1

2 release files

0.2.1

2 release files

0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page