Skip to content

Commit 9a2cfb0

Browse files
committed
Add documentation website
1 parent 11ef3e2 commit 9a2cfb0

File tree

9 files changed

+213
-138
lines changed

9 files changed

+213
-138
lines changed

README.md

Lines changed: 4 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Lightweight [MkDocs](https://www.mkdocs.org/) plugin to display git authors of a
1212

1313
> Authors: Jane Doe, John Doe
1414
15-
The plugin only considers authors of the current lines in the page ('surviving code' using `git blame`).
15+
See the [demo](https://timvink.github.io/mkdocs-git-authors-plugin/). The plugin only considers authors of the current lines in the page ('surviving code' using `git blame`).
1616

1717
Other MkDocs plugins that use information from git:
1818

@@ -37,143 +37,11 @@ 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-
## Usage
40+
## Documentation
4141

42-
### In supported themes
42+
See https://timvink.github.io/mkdocs-git-authors-plugin/
4343

44-
no supported themes *yet*.
45-
46-
### In markdown pages
47-
48-
You can use the following jinja tags to insert content into your markdown pages:
49-
50-
- ``{{ git_page_authors }}`` a summary of the authors of a page. Output wrapped in `<span class='git-page-authors'>`
51-
- ``{{ git_site_authors }}`` a summary of all authors of all pages in your site. Output wrapped in `<span class='git-site-authors'>`
52-
53-
For example, adding ``{{ git_page_authors }}`` will insert:
54-
55-
```html
56-
<span class='git-page-authors'><a href='mailto:[email protected]'>Jane Doe</a><a href='mailto:[email protected]'>John Doe</a></span>
57-
```
58-
59-
Which renders as:
60-
61-
> [Jane Doe](mailto:[email protected]), [John Doe](mailto:[email protected])
62-
63-
64-
### In theme customizations
65-
66-
[MkDocs](https://www.mkdocs.org/) offers possibilities to [customize an existing theme](https://www.mkdocs.org/user-guide/styling-your-docs/#customizing-a-theme).
67-
68-
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):
69-
70-
1) Create a new file `main.html` in `docs/theme`:
71-
72-
```html
73-
{% extends "base.html" %}
74-
75-
{% block disqus %}
76-
<div class="md-source-date">
77-
<small>
78-
Authors: {{ git_page_authors }}
79-
</small>
80-
</div>
81-
{% include "partials/integrations/disqus.html" %}
82-
{% endblock %}
83-
```
84-
85-
2) In `mkdocs.yml` make sure to specify the custom directory with the theme overrides:
86-
87-
```yml
88-
theme:
89-
name: material
90-
custom_dir: docs/theme/
91-
```
92-
93-
### In theme templates
94-
95-
To add more detailed git author information to your theme you can [customize a MkDocs theme](https://www.mkdocs.org/user-guide/styling-your-docs/#customizing-a-theme) or even [develop your own](https://www.mkdocs.org/user-guide/custom-themes/).
96-
97-
When enabling this plugin, you will have access to the jinja2 variable `git_info` which contains as dict with the following structure:
98-
99-
```python
100-
{
101-
'page_authors' : [
102-
{
103-
'name' : 'Jane Doe',
104-
'email' : '[email protected]',
105-
'last_datetime' : datetime.datetime(),
106-
'lines' : 200,
107-
'contribution' : '40.0%'
108-
},
109-
{
110-
'name' : 'John Doe',
111-
'email' : '[email protected]',
112-
'last_datetime' : datetime.datetime(),
113-
'lines' : 300,
114-
'contribution' : '60.0%'
115-
}
116-
],
117-
'site_authors' : # same structure
118-
}
119-
```
120-
121-
#### Example usage in theme development
122-
123-
An example of how to use in your templates:
124-
125-
```django hljs
126-
{% if git_info %}
127-
{%- for author in git_info.get('page_authors') -%}
128-
<a href="{{ author.email }}" title="{{ author.name }}">
129-
{{ author.name }}
130-
</a>,
131-
{%- endfor -%}
132-
{% endif %}
133-
```
134-
135-
Alternatively, you could use the simple pre-formatted `{{ git_page_authors }}` to insert a summary of the authors.
136-
137-
## Options
138-
139-
### `show_contribution`
140-
141-
If this option is set to `true` (default: `false`) the contribution of a author is
142-
printed as a percentage of (source file) lines per author. The output is
143-
suppressed if there is only *one* author for a page.
144-
145-
Example output:
146-
147-
* Authors: [John Doe](#) (33.33%), [Jane Doe](#) (66.67%) *(more than one author)*
148-
* Authors: [John Doe](#) *(one author)*
149-
150-
### `show_line_count`
151-
152-
If this option is set to `true` (default: `false`) the number of lines per author is shown.
153-
154-
### `count_empty_lines`
155-
156-
If this option is set to `true` (default: `false`) empty lines will count towards an authors' contribution.
157-
158-
## Tricks
159-
160-
### Aggregating Authors
161-
162-
In some repositories authors may have committed with differing name/email combinations.
163-
In order to prevent the output being split it is possible to aggregate authors on
164-
arbitrary elements by providing a file `.mailmap` in the repository's root directory.
165-
This is a feature of Git itself. The following example will aggregate the contributions
166-
of Jane Doe committed under two email addresses:
167-
168-
```
169-
# .mailmap
170-
171-
```
172-
173-
This will map commits made with the `private-email.com` to the company address. For more details
174-
and further options (e.g. mapping between different names or misspellings etc. see the
175-
[git-blame documentation](https://git-scm.com/docs/git-blame#_mapping_authors).
17644

17745
## Contributing
17846

179-
Very much open to contributions! Please read [CONTRIBUTING.md](CONTRIBUTING.md) before putting in any work.
47+
Very much open to contributions! Please read [contributing guide](https://timvink.github.io/mkdocs-git-authors-plugin/contributing.html) before putting in any work.

CONTRIBUTING.md renamed to docs/contributing.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,13 @@ mkdocs serve -f ./tests/basic_setup/mkdocs_complete_material.yml
4141

4242
Make sure your code *roughly* follows [PEP-8](https://www.python.org/dev/peps/pep-0008/) and keeps things consistent with the rest of the code. I recommended using [black](https://github.com/psf/black) to automatically format your code.
4343

44-
We use google-style docstrings.
44+
We use google-style docstrings.
45+
46+
47+
## Documentation site
48+
49+
Manually deployed by Tim Vink using
50+
51+
```bash
52+
mkdocs gh-deploy
53+
```

docs/index.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# mkdocs-git-authors-plugin
2+
3+
Lightweight MkDocs plugin to display git authors of a markdown page.
4+
5+
## Setup
6+
7+
Install the plugin using pip3:
8+
9+
```bash
10+
pip3 install mkdocs-git-authors-plugin
11+
```
12+
13+
Next, add the following lines to your `mkdocs.yml`:
14+
15+
```yml
16+
plugins:
17+
- search
18+
- git-authors
19+
```
20+
21+
> 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.

docs/mailmap.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Aggregating Authors
2+
3+
In some repositories authors may have committed with differing name/email combinations.
4+
In order to prevent the output being split it is possible to aggregate authors on
5+
arbitrary elements by providing a file `.mailmap` in the repository's root directory.
6+
This is a feature of Git itself. The following example will aggregate the contributions
7+
of Jane Doe committed under two email addresses:
8+
9+
```
10+
# .mailmap
11+
12+
```
13+
14+
This will map commits made with the `private-email.com` to the company address. For more details
15+
and further options (e.g. mapping between different names or misspellings etc. see the
16+
[git-blame documentation](https://git-scm.com/docs/git-blame#_mapping_authors).

docs/options.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Options
2+
3+
You can customize the plugin by setting options in your `mkdocs.yml` file. Here is an example of all the options this plugin offers:
4+
5+
```yml
6+
plugins:
7+
- print-site:
8+
show_contribution: true
9+
show_line_count: true
10+
count_empty_lines: true
11+
```
12+
13+
## `show_contribution`
14+
15+
If this option is set to `true` (default: `false`) the contribution of a author is
16+
printed as a percentage of (source file) lines per author. The output is
17+
suppressed if there is only *one* author for a page.
18+
19+
Example output:
20+
21+
* Authors: [John Doe](#) (33.33%), [Jane Doe](#) (66.67%) *(more than one author)*
22+
* Authors: [John Doe](#) *(one author)*
23+
24+
## `show_line_count`
25+
26+
If this option is set to `true` (default: `false`) the number of lines per author is shown.
27+
28+
## `count_empty_lines`
29+
30+
If this option is set to `true` (default: `false`) empty lines will count towards an authors' contribution.

docs/theme/main.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% extends "base.html" %}
2+
3+
{% block disqus %}
4+
<div class="md-source-date">
5+
<small>
6+
Authors: {{ git_page_authors }}
7+
</small>
8+
</div>
9+
{% include "partials/integrations/disqus.html" %}
10+
{% endblock %}

docs/usage.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Usage
2+
3+
## In supported themes
4+
5+
no supported themes *yet*.
6+
7+
## In markdown pages
8+
9+
You can use the following jinja tags to insert content into your markdown pages:
10+
11+
- <code>\{\{&nbsp;git_page_authors \}\}</code> a summary of the authors of a page. Output wrapped in `<span class='git-page-authors'>`
12+
- <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'>`
13+
14+
For example, adding <code>\{\{ git_page_authors \}\}</code> will insert:
15+
16+
```html
17+
<span class='git-page-authors'><a href='mailto:[email protected]'>Jane Doe</a><a href='mailto:[email protected]'>John Doe</a></span>
18+
```
19+
20+
Which renders as:
21+
22+
> [Jane Doe](mailto:[email protected]), [John Doe](mailto:[email protected])
23+
24+
25+
## In theme customizations
26+
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).
28+
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):
30+
31+
1) Create a new file `main.html` in `docs/theme`:
32+
33+
```html
34+
{% extends "base.html" %}
35+
36+
{% block disqus %}
37+
<div class="md-source-date">
38+
<small>
39+
Authors: {{ git_page_authors }}
40+
</small>
41+
</div>
42+
{% include "partials/integrations/disqus.html" %}
43+
{% endblock %}
44+
```
45+
46+
2) In `mkdocs.yml` make sure to specify the custom directory with the theme overrides:
47+
48+
```yml
49+
theme:
50+
name: material
51+
custom_dir: docs/theme/
52+
```
53+
54+
## In theme templates
55+
56+
To add more detailed git author information to your theme you can [customize a MkDocs theme](https://www.mkdocs.org/user-guide/styling-your-docs/#customizing-a-theme) or even [develop your own](https://www.mkdocs.org/user-guide/custom-themes/).
57+
58+
When enabling this plugin, you will have access to the jinja2 variable `git_info` which contains as dict with the following structure:
59+
60+
```python
61+
{
62+
'page_authors' : [
63+
{
64+
'name' : 'Jane Doe',
65+
'email' : '[email protected]',
66+
'last_datetime' : datetime.datetime(),
67+
'lines' : 200,
68+
'contribution' : '40.0%'
69+
},
70+
{
71+
'name' : 'John Doe',
72+
'email' : '[email protected]',
73+
'last_datetime' : datetime.datetime(),
74+
'lines' : 300,
75+
'contribution' : '60.0%'
76+
}
77+
],
78+
'site_authors' : # same structure
79+
}
80+
```
81+
82+
#### Example usage in theme development
83+
84+
An example of how to use in your templates:
85+
86+
```html
87+
{% if git_info %}
88+
{%- for author in git_info.get('page_authors') -%}
89+
<a href="{{ author.email }}" title="{{ author.name }}">
90+
{{ author.name }}
91+
</a>,
92+
{%- endfor -%}
93+
{% endif %}
94+
```
95+
96+
Alternatively, you could use the simple pre-formatted `{{ git_page_authors }}` to insert a summary of the authors.

mkdocs.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
site_name: "git-authors Plugin"
2+
site_description: "Plugin to add git info to MkDocs sites"
3+
use_directory_urls: false
4+
5+
# Theme
6+
theme:
7+
name: material
8+
custom_dir: docs/theme/
9+
10+
# Plugins
11+
plugins:
12+
- search
13+
- git-authors
14+
15+
nav:
16+
- index.md
17+
- usage.md
18+
- options.md
19+
- mailmap.md
20+
- Contributing: contributing.md
21+
22+
markdown_extensions:
23+
- markdown.extensions.codehilite

mkdocs_git_authors_plugin/git/page.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

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

9+
910
class Page(AbstractRepoObject):
1011
"""
1112
Results of git blame for a given file.
@@ -32,7 +33,8 @@ def __init__(self, repo: Repo, path: Path):
3233
self._process_git_blame()
3334
except GitCommandError:
3435
logger.warning(
35-
"[git-authors-plugin] %s has not been committed yet. Lines are not counted" % path
36+
"[git-authors-plugin] %s has not been committed yet. Lines are not counted"
37+
% path
3638
)
3739

3840
def add_total_lines(self, cnt: int = 1):

0 commit comments

Comments
 (0)