You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/howto/override-a-theme.md
+34-18Lines changed: 34 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
-
# Override a theme
1
+
# Customize a theme
2
2
3
3
You can [customize an existing theme](https://www.mkdocs.org/user-guide/styling-your-docs/#customizing-a-theme) by overriding blocks or partials. You might want to do this because your theme is not natively supported, or you would like more control on the formatting. Below are some examples to get you started.
4
4
5
-
## mkdocs theme
5
+
## Example: default `mkdocs` theme
6
6
7
7
To add a revision date to the default `mkdocs` theme, add a `overrides/partials` folder to your `docs` folder and update your `mkdocs.yml` file.
8
8
Then you can extend the base `mkdocs` theme by adding a new file `docs/overrides/content.html`:
@@ -39,9 +39,9 @@ Then you can extend the base `mkdocs` theme by adding a new file `docs/overrides
39
39
{% endif %}
40
40
```
41
41
42
-
## mkdocs-material theme
42
+
## Example: `mkdocs-material` theme
43
43
44
-
[mkdocs-material](https://squidfunk.github.io/mkdocs-material/) has native support for `git_revision_date_localized` and `git_created_date_localized`. You can [extend the mkdocs-material theme](https://squidfunk.github.io/mkdocs-material/customization/#extending-the-theme)by adding overriding the [`source-date.html`](https://github.com/squidfunk/mkdocs-material/blob/master/src/partials/source-date.html) partial as follows:
44
+
[mkdocs-material](https://squidfunk.github.io/mkdocs-material/) has native support for `git_revision_date_localized` and `git_created_date_localized`. If you want, you can customize further by [extending the mkdocs-material theme](https://squidfunk.github.io/mkdocs-material/customization/#extending-the-theme)and overriding the [`source-file.html`](https://github.com/squidfunk/mkdocs-material/blob/master/src/partials/source-file.html) partial as follows:
45
45
46
46
=== "mkdocs.yml"
47
47
@@ -51,13 +51,13 @@ Then you can extend the base `mkdocs` theme by adding a new file `docs/overrides
51
51
custom_dir: docs/overrides_material_theme
52
52
```
53
53
54
-
=== "docs/overrides/partials/source-date.html"
54
+
=== "docs/overrides/partials/source-file.html"
55
55
56
56
```html
57
57
{% import "partials/language.html" as lang with context %}
58
58
59
59
<!-- Last updated date -->
60
-
{% set label = lang.t("source.revision.date") %}
60
+
{% set label = lang.t("source.file.date.updated") %}
61
61
<hr />
62
62
<div class="md-source-date">
63
63
<small>
@@ -67,9 +67,9 @@ Then you can extend the base `mkdocs` theme by adding a new file `docs/overrides
@@ -78,19 +78,36 @@ Then you can extend the base `mkdocs` theme by adding a new file `docs/overrides
78
78
</div>
79
79
```
80
80
81
-
## custom themes
81
+
## Available variables
82
82
83
-
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, like so for example:
83
+
When customizing or [writing your own themes](https://www.mkdocs.org/user-guide/custom-themes/)`mkdocs-revision-date-localized-plugin` will make available the following jinja variables:
84
84
85
-
```django
86
-
{% if page.meta.git_revision_date_localized %}
87
-
Last update: {{ page.meta.git_revision_date_localized }}
88
-
{% endif %}
89
-
```
85
+
-`page.meta.git_revision_date_localized`
86
+
-`page.meta.git_creation_date_localized`
90
87
91
-
As a developer you might want access to more raw date formats that also do not have the `<span>` elements. You can also use:
88
+
To insert these variables in a partial/block/template, use the jinja2 bracks `{{` and `}}`. The values of these variables depend on the plugin options specified, and are wrapped in `<span>` elements. For example, when using `type: timeago` (see [options](../options.md)):
89
+
90
+
=== "input"
91
+
92
+
```django
93
+
{% if page.meta.git_revision_date_localized %}
94
+
Last update: {{ page.meta.git_revision_date_localized }}
95
+
{% endif %}
96
+
```
97
+
98
+
=== "output"
99
+
100
+
```django
101
+
Last update: <span class="timeago" datetime="2021-11-03T12:25:03+01:00" locale="en" timeago-id="5"></span>
102
+
```
103
+
104
+
!!! info "Note"
105
+
106
+
When `type: timeago` option is used, `mkdocs-revision-date-localized-plugin` adds [timeago.js](https://timeago.org/) to your mkdocs website, which dynamically inserts a value between the `<span>` elements like `2 weeks ago`.
107
+
108
+
109
+
As a developer you might want access to multiple 'raw' date types. These variables also do not have the `<span>` elements. You can use:
0 commit comments