Skip to content

Commit

Permalink
Explain how to add revision date to mkdocs default theme
Browse files Browse the repository at this point in the history
  • Loading branch information
timvink committed Sep 17, 2020
1 parent 84d3bbc commit 837c661
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,45 @@ In your markdown files you can use the `{{ git_revision_date_localized }}` tag a
Last update: {{ git_revision_date_localized }}
```

### Extending existing themes

You can [customize an existing theme](https://www.mkdocs.org/user-guide/styling-your-docs/#customizing-a-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:

```yml
theme:
name: mkdocs
custom_dir: docs/overrides
```

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

<details>
<summary>content.html</summary>

```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 %}
```
</details>

&nbsp;

### In custom themes

When writing your own [custom themes](https://www.mkdocs.org/user-guide/custom-themes/) you can use the `page.meta.git_revision_date_localized` jinja tag:
Expand Down
1 change: 1 addition & 0 deletions mkdocs_git_revision_date_localized_plugin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

logger = logging.getLogger("mkdocs.plugins")


class Util:
def __init__(self, path: str = ".", config={}):

Expand Down
16 changes: 16 additions & 0 deletions tests/fixtures/basic_project/docs/overrides/content.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!-- 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 %}
10 changes: 10 additions & 0 deletions tests/fixtures/basic_project/mkdocs_with_override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
site_name: test gitrevisiondatelocalized_plugin
use_directory_urls: true

theme:
name: mkdocs
custom_dir: docs/overrides

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

0 comments on commit 837c661

Please sign in to comment.