Skip to content

Commit 9244cce

Browse files
committed
Improve docs on using partials
1 parent 0ee544b commit 9244cce

File tree

5 files changed

+68
-24
lines changed

5 files changed

+68
-24
lines changed

docs/options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ You can customize the plugin by setting options in your `mkdocs.yml` file. Here
44

55
```yml
66
plugins:
7-
- print-site:
7+
- git-authors:
88
show_contribution: true
99
show_line_count: true
1010
count_empty_lines: true

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 }}
10+
</small>
11+
</div>
12+
{% endif %}
13+
{% endblock %}

docs/theme/main.html

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

docs/usage.md

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ You can use the following jinja tags to insert content into your markdown pages:
1111
- <code>\{\{&nbsp;git_page_authors \}\}</code> a summary of the authors of a page. Output wrapped in `<span class='git-page-authors'>`
1212
- <code>\{\{&nbsp;git_site_authors \}\}</code> a summary of all authors of all pages in your site. Output wrapped in `<span class='git-site-authors'>`
1313

14-
For example, adding <code>\{\{ git_page_authors \}\}</code> will insert:
14+
For example, adding <code>\{\{ git_page_authors \}\}</code> could insert:
1515

1616
```html
1717
<span class='git-page-authors'><a href='mailto:[email protected]'>Jane Doe</a><a href='mailto:[email protected]'>John Doe</a></span>
@@ -24,22 +24,27 @@ Which renders as:
2424

2525
## In theme customizations
2626

27-
[MkDocs](https://www.mkdocs.org/) offers possibilities to [customize an existing theme](https://www.mkdocs.org/user-guide/styling-your-docs/#customizing-a-theme).
27+
[MkDocs](https://www.mkdocs.org/) offers possibilities to [customize an existing theme](https://www.mkdocs.org/user-guide/styling-your-docs/#customizing-a-theme). See two examples below:
2828

29-
As an example, if you use [mkdocs-material](https://github.com/squidfunk/mkdocs-material) you can implement git-authors by [overriding a template block](https://squidfunk.github.io/mkdocs-material/customization/#overriding-template-blocks):
29+
### mkdocs-material theme
3030

31-
1) Create a new file `main.html` in `docs/theme`:
31+
If you use the [mkdocs-material](https://github.com/squidfunk/mkdocs-material) theme you can implement git-authors by [overriding a template block](https://squidfunk.github.io/mkdocs-material/customization/#overriding-blocks):
32+
33+
1) Create a new file `main.html` in `docs/overrides`:
3234

3335
```html
3436
{% extends "base.html" %}
3537

36-
{% block disqus %}
38+
{% block content %}
39+
{{ super() }}
40+
41+
{% if git_page_authors %}
3742
<div class="md-source-date">
38-
<small>
39-
Authors: {{ git_page_authors }}
40-
</small>
41-
</div>
42-
{% include "partials/integrations/disqus.html" %}
43+
<small>
44+
Authors: {{ git_page_authors }}
45+
</small>
46+
</div>
47+
{% endif %}
4348
{% endblock %}
4449
```
4550

@@ -48,7 +53,40 @@ As an example, if you use [mkdocs-material](https://github.com/squidfunk/mkdocs-
4853
```yml
4954
theme:
5055
name: material
51-
custom_dir: docs/theme/
56+
custom_dir: docs/overrides
57+
```
58+
59+
### mkdocs theme
60+
61+
In the default MkDocs theme we can use overriding partials to add the git-authors info below the page content.
62+
63+
1) Create a new file `content.html` in `docs/overrides`:
64+
65+
```html
66+
<!-- Overwrites content.html base mkdocs theme, taken from
67+
https://github.com/mkdocs/mkdocs/blob/master/mkdocs/themes/mkdocs/content.html -->
68+
69+
{% if page.meta.source %}
70+
<div class="source-links">
71+
{% for filename in page.meta.source %}
72+
<span class="label label-primary">{{ filename }}</span>
73+
{% endfor %}
74+
</div>
75+
{% endif %}
76+
77+
{{ page.content }}
78+
79+
{% if git_page_authors %}
80+
<p><small>Authors: {{ git_page_authors }}</small></p>
81+
{% endif %}
82+
```
83+
84+
2) In `mkdocs.yml` make sure to specify the custom directory with the theme overrides:
85+
86+
```yml
87+
theme:
88+
name: mkdocs
89+
custom_dir: docs/overrides
5290
```
5391

5492
## In theme templates

mkdocs.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ use_directory_urls: false
55
# Theme
66
theme:
77
name: material
8-
custom_dir: docs/theme/
8+
custom_dir: docs/overrides
99

1010
# Plugins
1111
plugins:
1212
- search
13-
- git-authors
13+
- git-authors:
14+
show_contribution: true
15+
show_line_count: true
16+
count_empty_lines: true
1417

1518
nav:
1619
- index.md

0 commit comments

Comments
 (0)