Skip to content

Adding a git repository

If your documentation is related to source code, MaterialX 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/jaywhj/mkdocs-materialx

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 latest release tag1, as well as the number of stars and forks, are automatically requested and rendered.

Repository name

0.1.0 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: jaywhj/mkdocs-materialx

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:

      Markdown for AI agents

      10.1.5

      Now, GEO (SEO applied to AI agents) is becoming an important stake for websites discoverability. To allow AI agents (Claude Code, ChatGPT, etc.) to access pages more effectively, you can use the following configuration to let AI agents directly fetch the page Markdown source.

      This provides AI with well-structured content, reduces token consumption by over 80%, and greatly cuts down irrelevant noise.

      theme:
        features:
          - content.action.agents
      

      After applying this configuration, an HTML link relation of type text/markdown will be automatically generated in the page header:

      <link rel="alternate" type="text/markdown" href="https://github.com/xxx.md">
      

      Note

      • This feature relies on the repo_url and edit_uri settings, you need to configure both properties correctly
      • If the default branch of your GitHub repository is main, add the configuration:

        edit_uri: edit/main/docs/
        

      Related introduction: Introducing Markdown for Agents

      Document dates & authors

      10.0.4 document-dates

      You can add date and author information to your documents via the next-generation Date & Author plugin document-dates.

      render

      For more details: Date & authors

      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: jaywhj/mkdocs-materialx
            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: jaywhj/mkdocs-materialx
      
      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 MaterialX for MkDocs, which is why they may yield unexpected results. Use them at your own risk.


      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. For GitLab, although it is possible to get a list of tags sorted by update time, the equivalent API endpoint is used. So, make sure you also create a release for GitLab repositories

      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.