Անցնել պարունակությանը

Adding a git repository

If your documentation is related to source code, Material for MkDocs provides the ability to display information to the project's repository as part of the static site, including stars and forks. Furthermore, the date of last update and creation, as well as contributors can be shown.

Configuration

Repository

0.1.0

In order to display a link to the repository of your project as part of your documentation, set repo_url in mkdocs.yml to the public URL of your repository, e.g.:

repo_url: https://github.com/squidfunk/mkdocs-material

The link to the repository will be rendered next to the search bar on big screens and as part of the main navigation drawer on smaller screen sizes. Additionally, for public repositories hosted on GitHub or GitLab, the number of stars and forks is automatically requested and rendered.

GitHub repositories also include the tag of the latest release.1

Repository name

0.1.0 automatically set to GitHub, GitLab or Bitbucket

MkDocs will infer the source provider by examining the URL and try to set the repository name automatically. If you wish to customize the name, set repo_name in mkdocs.yml:

repo_name: squidfunk/mkdocs-material

Repository icon

5.0.0

While the default repository icon is a generic git icon, it can be set to any icon bundled with the theme by referencing a valid icon path in mkdocs.yml:

theme:
  icon:
    repo: fontawesome/brands/git-alt # (1)!
  1. Enter a few keywords to find the perfect icon using our icon search and click on the shortcode to copy it to your clipboard:

    Some popular choices:

    • fontawesome/brands/git
    • fontawesome/brands/git-alt
    • fontawesome/brands/github
    • fontawesome/brands/github-alt
    • fontawesome/brands/gitlab
    • fontawesome/brands/gitkraken
    • fontawesome/brands/bitbucket
    • fontawesome/solid/trash

    Code actions

    9.0.0

    If the repository URL points to a valid GitHub, GitLab or Bitbucket repository, MkDocs provides a setting called edit_uri, which resolves to the subfolder where your documentation is hosted.

    If your default branch is called main, change the setting to:

    edit_uri: edit/main/docs/
    

    After making sure that edit_uri is correctly configured, buttons for code actions can be added. Two types of code actions are supported: edit and view (GitHub only):

    theme:
      features:
        - content.action.edit
    
    theme:
      features:
        - content.action.view
    

    The icon of the edit and view buttons can be changed with the following lines:

    theme:
      icon:
        edit: material/pencil # (1)!
        view: material/eye
    
    1. Enter a few keywords to find the perfect icon using our icon search and click on the shortcode to copy it to your clipboard:

      Revisioning

      The following plugins are fully integrated with Material for MkDocs, allowing for showing the date of last update and creation of a document, as well as links to all contributors or authors involved.

      Document dates

      4.6.0 git-revision-date-localized

      The git-revision-date-localized plugin adds support for adding the date of last update and creation of a document at the bottom of each page. Install it with pip:

      pip install mkdocs-git-revision-date-localized-plugin
      

      Then, add the following lines to mkdocs.yml:

      plugins:
        - git-revision-date-localized:
            enable_creation_date: true
      

      The following configuration options are supported:

      enabled

      true This option specifies whether the plugin is enabled when building your project. If you want to switch the plugin off, e.g. for local builds, use an environment variable:

      plugins:
        - git-revision-date-localized:
            enabled: !ENV [CI, false]
      
      type

      date The format of the date to be displayed. Valid values are date, datetime, iso_date, iso_datetime and timeago:

      plugins:
        - git-revision-date-localized:
            type: date
      
      enable_creation_date

      false Enables the display of the creation date of the file associated with the page next to the last updated date at the bottom of the page:

      plugins:
        - git-revision-date-localized:
            enable_creation_date: true
      

      When using build environments

      If you are deploying through a CI system, you might need to adjust your CI settings when fetching the code. For more information, see git-revision-date-localized.

      fallback_to_build_date

      false Enables falling back to the time when mkdocs build was executed. Can be used as a fallback when the build is performed outside of a git repository:

      plugins:
        - git-revision-date-localized:
            fallback_to_build_date: true
      

      The other configuration options of this extension are not officially supported by Material for MkDocs, which is why they may yield unexpected results. Use them at your own risk.

      Document contributors

      9.5.0 git-committers

      The git-committers2 plugin renders the GitHub avatars of all contributors, linking to their GitHub profiles at the bottom of each page. As always, it can be installed with pip:

      pip install mkdocs-git-committers-plugin-2
      

      Then, add the following lines to mkdocs.yml:

      plugins:
        - git-committers:
            repository: squidfunk/mkdocs-material
            branch: main
      

      The following configuration options are supported:

      enabled

      true This option specifies whether the plugin is enabled when building your project. If you want to switch the plugin off, e.g. for local builds, use an environment variable:

      plugins:
        - git-committers:
            enabled: !ENV [CI, false]
      
      repository

      This property must be set to the slug of the repository that contains your documentation. The slug must follow the pattern <username>/<repository>:

      plugins:
        - git-committers:
            repository: squidfunk/mkdocs-material
      
      branch

      master This property should be set to the branch of the repository from which to retrieve the contributors. To use the main branch:

      plugins:
        - git-committers:
            branch: main
      

      The other configuration options of this extension are not officially supported by Material for MkDocs, which is why they may yield unexpected results. Use them at your own risk.

      Document authors

      9.5.0 git-authors

      The git-authors plugin is a lightweight alternative to the git-committers plugin and extracts the authors of a document from git to display them at the bottom of each page.

      Material for MkDocs offers deep integration for git-authors. This means the customized overrides are not necessary, and additional styling (such as nice icons) are added. Simply install it with pip:

      pip install mkdocs-git-authors-plugin
      

      Then, add the following lines to mkdocs.yml:

      plugins:
        - git-authors
      

      1. Unfortunately, GitHub only provides an API endpoint to obtain the latest release - not the latest tag. Thus, make sure to create a release (not pre-release) for the latest tag you want to display next to the number of stars and forks. 

      2. We currently recommend using a fork of the git-committers plugin, as it contains many improvements that have not yet been merged back into the original plugin. See byrnereese/mkdocs-git-committers-plugin#12 for more information.