Skip to content

Commit 837c661

Browse files
committed
Explain how to add revision date to mkdocs default theme
1 parent 84d3bbc commit 837c661

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

Diff for: README.md

+39
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,45 @@ In your markdown files you can use the `{{ git_revision_date_localized }}` tag a
5858
Last update: {{ git_revision_date_localized }}
5959
```
6060

61+
### Extending existing themes
62+
63+
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.
64+
65+
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:
66+
67+
```yml
68+
theme:
69+
name: mkdocs
70+
custom_dir: docs/overrides
71+
```
72+
73+
And then adding a new file `docs/overrides/content.html` with the following content:
74+
75+
<details>
76+
<summary>content.html</summary>
77+
78+
```html
79+
<!-- Overwrites content.html base mkdocs theme, taken from
80+
https://github.com/mkdocs/mkdocs/blob/master/mkdocs/themes/mkdocs/content.html -->
81+
82+
{% if page.meta.source %}
83+
<div class="source-links">
84+
{% for filename in page.meta.source %}
85+
<span class="label label-primary">{{ filename }}</span>
86+
{% endfor %}
87+
</div>
88+
{% endif %}
89+
90+
{{ page.content }}
91+
92+
{% if page.meta.git_revision_date_localized %}
93+
<small>Last update: {{ page.meta.git_revision_date_localized }}</small>
94+
{% endif %}
95+
```
96+
</details>
97+
98+
&nbsp;
99+
61100
### In custom themes
62101

63102
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:

Diff for: mkdocs_git_revision_date_localized_plugin/util.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

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

12+
1213
class Util:
1314
def __init__(self, path: str = ".", config={}):
1415

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!-- Overwrites content.html base mkdocs theme, taken from
2+
https://github.com/mkdocs/mkdocs/blob/master/mkdocs/themes/mkdocs/content.html -->
3+
4+
{% if page.meta.source %}
5+
<div class="source-links">
6+
{% for filename in page.meta.source %}
7+
<span class="label label-primary">{{ filename }}</span>
8+
{% endfor %}
9+
</div>
10+
{% endif %}
11+
12+
{{ page.content }}
13+
14+
{% if page.meta.git_revision_date_localized %}
15+
<small>Last update: {{ page.meta.git_revision_date_localized }}</small>
16+
{% endif %}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
site_name: test gitrevisiondatelocalized_plugin
2+
use_directory_urls: true
3+
4+
theme:
5+
name: mkdocs
6+
custom_dir: docs/overrides
7+
8+
plugins:
9+
- search
10+
- git-revision-date-localized

0 commit comments

Comments
 (0)