Skip to content

Commit b6b0d11

Browse files
authored
Merge pull request #66 from timvink/19-add-site-last-update
Add new variables for site revision date
2 parents 22ff2e4 + 70df745 commit b6b0d11

File tree

14 files changed

+174
-132
lines changed

14 files changed

+174
-132
lines changed

.github/workflows/pythonpublish.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v2
12+
with:
13+
fetch_depth: '0'
1214
- name: Set up Python
1315
uses: actions/setup-python@v2
1416
with:
@@ -35,4 +37,5 @@ jobs:
3537
3638
- name: Deploy mkdocs site
3739
run: |
40+
pip install mkdocs-git-authors-plugin
3841
mkdocs gh-deploy --force

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ plugins:
3737
3838
> 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.
3939

40-
If you use the [mkdocs-material](https://squidfunk.github.io/mkdocs-material/) theme, you should already see the last revision on the bottom of your pages.
40+
The [mkdocs-material](https://squidfunk.github.io/mkdocs-material/) theme has built in support for `git-revision-date-localized` and you should already see the last revision date on the bottom of your pages. See the [documentation](https://timvink.github.io/mkdocs-git-revision-date-localized-plugin/index.html) on how to fine-tune the appearance and the date format.
4141

4242
### Note when using build environments
4343

docs/available-variables.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Available variables
2+
3+
This plugin offers the following variables:
4+
5+
| timestamp | description |
6+
|:-----------|:------------|
7+
| `git-revision-date-localized` | Last git commit that touched a file. Enabled by default. |
8+
| `git-creation-date-localized` | First git commit that touched a file. Enable in [options](options.md). |
9+
| `git_site_revision_date_localized` | Last git commit that touched any file in the `docs/` folder. Enabled by default. |
10+
11+
You can use these variables wrapped in curly brackets (`{{` and `}}`) anywhere in a markdown file, like so:
12+
13+
<pre id="__code_42"><span></span><button class="md-clipboard md-icon" title="Copy to clipboard" data-clipboard-target="#__code_42 > code"></button><code>This page was last updated: *&#123;{ git_revision_date_localized }}*
14+
</code></pre>
15+
16+
Example output: This page was last updated *{{ git_revision_date_localized }}*.
17+
18+
Changing the `type`, `timezone` and/or `locale` in the [options](options.md) will effect the output of these variables. To change the styling see [Applying custom styling](howto/custom-styling.md).
19+
20+
## Variables for overriding themes
21+
22+
If you do not want to include revision dates manually in each markdown file, or if you would like more control on the formatting, you can [override a theme](howto/override-a-theme.md). You can use the same three variables but with a `page.meta.` prefix:
23+
24+
- `page.meta.git-revision-date-localized`
25+
- `page.meta.git-creation-date-localized`
26+
- `page.meta.git_revision_date_localized_raw_date`
27+
28+
To allow for more flexibility when overriding a theme there are also variables for each different `type` available (regardless of the setting for `type` in [options](options.md)), where the output is also not wrapped in `<span>` elements (so you can do the CSS styling yourself):
29+
30+
- `page.meta.git_revision_date_localized_raw_date`
31+
- `page.meta.git_revision_date_localized_raw_datetime`
32+
- `page.meta.git_revision_date_localized_raw_iso_date`
33+
- `page.meta.git_revision_date_localized_raw_iso_datetime`
34+
- `page.meta.git_revision_date_localized_raw_timeago`
35+
- `page.meta.git_site_revision_date_localized_raw_datetime`
36+
- `page.meta.git_site_revision_date_localized_raw_iso_date`
37+
- `page.meta.git_site_revision_date_localized_raw_date`
38+
- `page.meta.git_site_revision_date_localized_raw_iso_datetime`
39+
- `page.meta.git_site_revision_date_localized_raw_timeago`
40+
41+
And if you've enable creation date in the config:
42+
43+
- `page.meta.git_creation_date_localized_raw_date`
44+
- `page.meta.git_creation_date_localized_raw_datetime`
45+
- `page.meta.git_creation_date_localized_raw_iso_date`
46+
- `page.meta.git_creation_date_localized_raw_iso_datetime`
47+
- `page.meta.git_creation_date_localized_raw_timeago`

docs/getting-started.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

docs/howto/custom-styling.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
11
# Apply custom styling
22

3-
You might want to change the appearance of the dates in your theme. You can style the output using CSS, for example by [including extra css](https://www.mkdocs.org/user-guide/configuration/#extra_css) to your mkdocs site.
3+
You can change the appearance of the revision dates by [including extra CSS](https://www.mkdocs.org/user-guide/configuration/#extra_css) to your mkdocs site.
44

5-
The date outputs are always wrapped in `span` elements with the classes `git-revision-date-localized-plugin` and `git-revision-date-localized-plugin-{type}` (where `{type}` is replaced with the `type` option set in the plugin).
5+
## CSS Classes
66

7-
Here's an example:
7+
To allow for easier styling date outputs are wrapped in `<span>` elements with the classes `git-revision-date-localized-plugin` and `git-revision-date-localized-plugin-{type}`, where `{type}` is replaced with the `type` set in the plugin settings (see [options](../options.md)).
88

9-
=== "mkdocs.yml"
9+
For example when `type: datetime` is set, using the following in a markdown file:
1010

11-
```yaml
12-
extra_css:
13-
css/extra.css
14-
```
11+
<pre id="__code_42"><span></span><button class="md-clipboard md-icon" title="Copy to clipboard" data-clipboard-target="#__code_42 > code"></button><code>Last update: {{ git_revision_date_localized }&#125;
12+
</code></pre>
13+
14+
Could output the following HTML:
15+
16+
```django
17+
Last update:
18+
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-datetime">28 November, 2019 13:57:28</span>
19+
```
20+
21+
## Customizing a class
1522

16-
=== "docs/css/extra.css"
23+
Making all revision dates red is as easy as:
24+
25+
=== ":octicons-file-code-16: docs/css/extra.css"
1726

1827
```css
1928
.git-revision-date-localized-plugin { color: red; }
2029
```
2130

31+
=== ":octicons-file-code-16: mkdocs.yml"
32+
33+
```yaml
34+
extra_css:
35+
css/extra.css
36+
```
37+

docs/howto/override-a-theme.md

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# Customize a theme
22

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.
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 two examples to help get you started.
44

55
## Example: default `mkdocs` theme
66

77
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.
88
Then you can extend the base `mkdocs` theme by adding a new file `docs/overrides/content.html`:
99

10-
=== "mkdocs.yml"
10+
=== ":octicons-file-code-16: mkdocs.yml"
1111

12-
```yml
12+
```yaml
1313
theme:
1414
name: mkdocs
1515
custom_dir: docs/overrides
1616
```
1717

18-
=== "docs/overrides/content.html"
18+
=== ":octicons-file-code-16: docs/overrides/content.html"
1919

2020
```html
2121
<!-- Overwrites content.html base mkdocs theme, taken from
@@ -31,6 +31,7 @@ Then you can extend the base `mkdocs` theme by adding a new file `docs/overrides
3131

3232
{{ page.content }}
3333

34+
<!-- This section adds support for localized revision dates -->
3435
{% if page.meta.git_revision_date_localized %}
3536
<small>Last update: {{ page.meta.git_revision_date_localized }}</small>
3637
{% endif %}
@@ -41,17 +42,19 @@ Then you can extend the base `mkdocs` theme by adding a new file `docs/overrides
4142

4243
## Example: `mkdocs-material` theme
4344

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+
[mkdocs-material](https://squidfunk.github.io/mkdocs-material/) has built-in support for `git_revision_date_localized` and `git_created_date_localized`. You can see that when viewing their [`source-file.html`](https://github.com/squidfunk/mkdocs-material/blob/master/src/partials/source-file.html) partial.
4546

46-
=== "mkdocs.yml"
47+
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` partial as follows:
4748

48-
```yml
49+
=== ":octicons-file-code-16: mkdocs.yml"
50+
51+
```yaml
4952
theme:
5053
name: 'material'
51-
custom_dir: docs/overrides_material_theme
54+
custom_dir: docs/overrides
5255
```
5356

54-
=== "docs/overrides/partials/source-file.html"
57+
=== ":octicons-file-code-16: docs/overrides/partials/source-file.html"
5558

5659
```html
5760
{% import "partials/language.html" as lang with context %}
@@ -69,55 +72,7 @@ Then you can extend the base `mkdocs` theme by adding a new file `docs/overrides
6972
{% if page.meta.git_creation_date_localized %}
7073
<br />{{ lang.t("source.file.date.created") }}: {{ page.meta.git_creation_date_localized }}
7174
{% endif %}
72-
73-
<!-- mkdocs-git-revision-date-plugin -->
74-
{% elif page.meta.revision_date %}
75-
{{ label }}: {{ page.meta.revision_date }}
76-
{% endif %}
7775
</small>
7876
</div>
7977
```
8078

81-
## Available variables
82-
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-
85-
- `page.meta.git_revision_date_localized`
86-
- `page.meta.git_creation_date_localized`
87-
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:
110-
111-
- `page.meta.git_revision_date_localized_raw_date`
112-
- `page.meta.git_revision_date_localized_raw_datetime`
113-
- `page.meta.git_revision_date_localized_raw_iso_date`
114-
- `page.meta.git_revision_date_localized_raw_iso_datetime`
115-
- `page.meta.git_revision_date_localized_raw_timeago`
116-
117-
And if you've enable creation date in the config:
118-
119-
- `page.meta.git_creation_date_localized_raw_date`
120-
- `page.meta.git_creation_date_localized_raw_datetime`
121-
- `page.meta.git_creation_date_localized_raw_iso_date`
122-
- `page.meta.git_creation_date_localized_raw_iso_datetime`
123-
- `page.meta.git_creation_date_localized_raw_timeago`

docs/options.md

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,26 @@
22

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

5-
```yaml
6-
plugins:
7-
- git-revision-date-localized:
8-
type: timeago
9-
timezone: Europe/Amsterdam
10-
locale: en
11-
fallback_to_build_date: false
12-
enable_creation_date: true
13-
exclude:
14-
- index.md
15-
enabled: true
16-
```
5+
=== ":octicons-file-code-16: mkdocs.yml"
6+
7+
```yaml
8+
plugins:
9+
- git-revision-date-localized:
10+
type: timeago
11+
timezone: Europe/Amsterdam
12+
locale: en
13+
fallback_to_build_date: false
14+
enable_creation_date: true
15+
exclude:
16+
- index.md
17+
enabled: true
18+
```
1719
1820
## `type`
1921

2022
Default is `date`. The format of the date to be displayed. Valid values are `date`, `datetime`, `iso_date`, `iso_datetime` and `timeago`. Example outputs:
2123

22-
```
24+
```yaml
2325
28 November, 2019 # type: date (default)
2426
28 November, 2019 13:57:28 # type: datetime
2527
2019-11-28 # type: iso_date
@@ -41,7 +43,7 @@ Default is `None`. Specify a two letter [ISO639](https://en.wikipedia.org/wiki/L
4143

4244
Example outputs:
4345

44-
```
46+
```yaml
4547
27 April, 2021 # `locale: en` with `type: date` (default)
4648
27 April, 2021 13:11:28 # `locale: en` with `type: datetime`
4749
2 weeks ago # `locale: en` with `type: timeago`
@@ -56,33 +58,35 @@ Default is `false`. Enables falling back to the time when `mkdocs build` was exe
5658

5759
## `enable_creation_date`
5860

59-
Default is `false`. Enables adding a *Created* date at the bottom of each page on [supported themes](getting-started.md#supported-themes). Also enables use of <code>\{\{ git_creation_date_localized }}</code> in markdown files and `page.meta.git_creation_date_localized` in page templates.
61+
Default is `false` (because it has a small effect on build time). Enables adding a *Created* date at the bottom of each page on [supported themes](getting-started.md#supported-themes). Also enables use of <code>\{\{ git_creation_date_localized }}</code> in markdown files and `page.meta.git_creation_date_localized` in page templates.
6062

6163
## `exclude`
6264

6365
Default is empty. Specify a list of page source paths (one per line) that should not have a revision date included (excluded from processing by this plugin). This can be useful for example to remove the revision date from the front page. The source path of a page is relative to your `docs/` folder. You can also use [globs](https://docs.python.org/3/library/glob.html) instead of full source paths. To exclude `docs/subfolder/page.md` specify in your `mkdocs.yml` a line under `exclude:` with `- subfolder/page.md`. Some examples:
6466

65-
```yaml
66-
# mkdocs.yml
67-
plugins:
68-
- git-revision-date-localized:
69-
exclude:
70-
- index.md
71-
- subfolder/page.md
72-
- another_page.md
73-
- folder/*
74-
```
67+
=== ":octicons-file-code-16: mkdocs.yml"
68+
69+
```yaml
70+
plugins:
71+
- git-revision-date-localized:
72+
exclude:
73+
- index.md
74+
- subfolder/page.md
75+
- another_page.md
76+
- folder/*
77+
```
7578
7679
## `enabled`
7780

7881
Default is `true`. Enables you to deactivate this plugin. A possible use case is local development where you might want faster build times and/or do not have git available. It's recommended to use this option with an environment variable together with a default fallback (introduced in `mkdocs` v1.2.1, see [docs](https://www.mkdocs.org/user-guide/configuration/#environment-variables)). Example:
7982

80-
```yaml
81-
# mkdocs.yml
82-
plugins:
83-
- git-revision-date-localized:
84-
enabled: !ENV [ENABLED_GIT_REVISION_DATE, True]
85-
```
83+
=== ":octicons-file-code-16: mkdocs.yml"
84+
85+
```yaml
86+
plugins:
87+
- git-revision-date-localized:
88+
enabled: !ENV [ENABLED_GIT_REVISION_DATE, True]
89+
```
8690

8791
Which enables you do disable the plugin locally using:
8892

docs/overrides/main.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
{{ super() }}
5+
6+
{% if git_page_authors %}
7+
<div class="md-source-date">
8+
<small>
9+
Authors: {{ git_page_authors | default('enable mkdocs-git-authors-plugin') }}
10+
</small>
11+
</div>
12+
{% endif %}
13+
{% endblock %}

0 commit comments

Comments
 (0)