Skip to main content

Mkdocs plugin to display git authors of a page

Project description

Actions Status PyPI - Python Version PyPI PyPI - Downloads codecov GitHub contributors PyPI - License

mkdocs-git-authors-plugin

Lightweight MkDocs plugin to display git authors of a markdown page:

Authors: Jane Doe, John Doe

The plugin only considers authors of the current lines in the page ('surviving code' using git blame).

Other MkDocs plugins that use information from git:

Setup

Install the plugin using pip3:

pip3 install mkdocs-git-authors-plugin

Next, add the following lines to your mkdocs.yml:

plugins:
  - search
  - git-authors

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.

Usage

In supported themes

no supported themes yet.

In markdown pages

You can use the following jinja tags to insert content into your markdown pages:

  • {{ git_page_authors }} a summary of the authors of a page. Output wrapped in <span class='git-page-authors'>
  • {{ git_site_authors }} a summary of all authors of all pages in your site. Output wrapped in <span class='git-site-authors'>

For example, adding {{ git_page_authors }} will insert:

<span class='git-page-authors'><a href='mailto:jane@abc.com'>Jane Doe</a><a href='mailto:john@abc.com'>John Doe</a></span>

Which renders as:

Jane Doe, John Doe

In theme customizations

MkDocs offers possibilities to customize an existing theme.

As an example, if you use mkdocs-material you can implement git-authors by overriding a template block:

  1. Create a new file base.html in docs/assets/theme:
{% extends "base.html" %}

{% block disqus %}
    <div class="md-source-date">
    <small>
        Authors: {{ git_page_authors }}
    </small>
  </div>
    {% include "partials/integrations/disqus.html" %}
{% endblock %}
  1. In mkdocs.yml make sure to specify the custom directory with the theme overrides:
theme:
    name: material
    custom_dir: docs/assets/theme/

In theme templates

To add more detailed git author information to your theme you can customize a MkDocs theme or even develop your own.

When enabling this plugin, you will have access to the jinja2 variable git_info which contains as dict with the following structure:

{
  'page_authors' : [
    {
    'name' : 'Jane Doe',
    'email' : 'jane@abc.com',
    'last_datetime' : datetime.datetime(),
    'lines' : 200,
    'contribution' : '40.0%'
  },
  {
    'name' : 'John Doe',
    'email' : 'john@abc.com',
    'last_datetime' : datetime.datetime(),
    'lines' : 300,
    'contribution' : '60.0%'
  }
 ],
 'site_authors' : # same structure
}

Example usage in theme development

An example of how to use in your templates:

{% if git_info %}
  {%- for author in git_info.get('page_authors') -%}
    <a href="{{ author.email }}" title="{{ author.name }}">
      {{ author.name }}
    </a>,
  {%- endfor -%}
{% endif %}

Alternatively, you could use the simple pre-formatted {{ git_page_authors }} to insert a summary of the authors.

Options

show_contribution

If this option is set to true (default: false) the contribution of a author is printed as a percentage of (source file) lines per author. The output is suppressed if there is only one author for a page.

Example output:

show_line_count

If this option is set to true (default: false) the number of lines per author is shown.

count_empty_lines

If this option is set to true (default: false) empty lines will count towards an authors' contribution.

Tricks

Aggregating Authors

In some repositories authors may have committed with differing name/email combinations. In order to prevent the output being split it is possible to aggregate authors on arbitrary elements by providing a file .mailmap in the repository's root directory. This is a feature of Git itself. The following example will aggregate the contributions of Jane Doe committed under two email addresses:

# .mailmap
Jane Doe <jane.doe@company.com> <jane.doe@private-email.com>

This will map commits made with the private-email.com to the company address. For more details and further options (e.g. mapping between different names or misspellings etc. see the git-blame documentation.

Contributing

Very much open to contributions! Please read CONTRIBUTING.md before putting in any work.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mkdocs-git-authors-plugin-0.3.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mkdocs_git_authors_plugin-0.3.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs-git-authors-plugin-0.3.0.tar.gz.

File metadata

  • Download URL: mkdocs-git-authors-plugin-0.3.0.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2

File hashes

Hashes for mkdocs-git-authors-plugin-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c165a2e0af562513fdae45fc4d4034e8668547c5abbc47aabfb661fee09fa30d
MD5 75a2a3b7e9573ed8315a15d957c64155
BLAKE2b-256 813503e89538939ee636df5595719bee47fb2b8ced61b0ed07bbb27f7f289728

See more details on using hashes here.

File details

Details for the file mkdocs_git_authors_plugin-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: mkdocs_git_authors_plugin-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2

File hashes

Hashes for mkdocs_git_authors_plugin-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4c707db217886f65c3f0f7992c58a90b990e8ce7a596d8e99f22180e394a6ae3
MD5 580757ada906137622ebc1b8e337a49a
BLAKE2b-256 1b17ce42687c863fe13981002e4d9077cd7a9852a7667321a605229596ecd4f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page