1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-12-30 00:03:23 +01:00
mkdocs-material/docs/setup/adding-a-git-repository.md

351 lines
11 KiB
Markdown
Raw Normal View History

# 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
2022-06-24 14:38:01 +02:00
static site, including stars and forks. Furthermore, the
[date of last update and creation], as well as [contributors] can be shown.
## Configuration
2021-10-10 22:32:32 +02:00
### Repository
2023-09-14 19:09:18 +02:00
<!-- md:version 0.1.0 -->
<!-- md:default none -->
2021-10-10 22:32:32 +02:00
In order to display a link to the repository of your project as part of your
2021-10-10 22:32:32 +02:00
documentation, set [`repo_url`][repo_url] in `mkdocs.yml` to the public URL of
your repository, e.g.:
``` yaml
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.
2021-10-10 22:32:32 +02:00
Additionally, for public repositories hosted on [GitHub] or [GitLab], the
number of stars and forks is automatically requested and rendered.
2022-04-02 15:10:50 +02:00
GitHub repositories also include the tag of the latest release.[^1]
[^1]:
Unfortunately, GitHub only provides an API endpoint to obtain the [latest
2023-09-14 19:09:18 +02:00
release] - not the latest tag. Thus, make sure to [create a release] (not
2022-06-24 14:38:01 +02:00
pre-release) for the latest tag you want to display next to the number of
2022-04-02 15:10:50 +02:00
stars and forks.
2021-10-10 22:32:32 +02:00
[repo_url]: https://www.mkdocs.org/user-guide/configuration/#repo_url
2022-04-02 15:10:50 +02:00
[latest release]: https://docs.github.com/en/rest/reference/releases#get-the-latest-release
[create a release]: https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository#creating-a-release
2022-06-24 14:38:01 +02:00
#### Repository name
2023-09-14 19:09:18 +02:00
<!-- md:version 0.1.0 -->
<!-- md:default _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
2021-10-10 22:32:32 +02:00
[`repo_name`][repo_name] in `mkdocs.yml`:
``` yaml
repo_name: squidfunk/mkdocs-material
```
2021-10-10 22:32:32 +02:00
[repo_name]: https://www.mkdocs.org/user-guide/configuration/#repo_name
2022-06-24 14:38:01 +02:00
#### Repository icon
2023-09-14 19:09:18 +02:00
<!-- md:version 5.0.0 -->
<!-- md:default computed -->
2021-10-10 22:32:32 +02:00
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`:
``` yaml
theme:
icon:
2022-01-16 17:30:25 +01:00
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:
<div class="mdx-iconsearch" data-mdx-component="iconsearch">
<input class="md-input md-input--stretch mdx-iconsearch__input" placeholder="Search icon" data-mdx-component="iconsearch-query" value="git" />
<div class="mdx-iconsearch-result" data-mdx-component="iconsearch-result" data-mdx-mode="file">
<div class="mdx-iconsearch-result__meta"></div>
<ol class="mdx-iconsearch-result__list"></ol>
</div>
</div>
2020-07-21 16:01:22 +02:00
Some popular choices:
2020-11-15 22:25:11 +01:00
- :fontawesome-brands-git: `fontawesome/brands/git`
- :fontawesome-brands-git-alt: `fontawesome/brands/git-alt`
- :fontawesome-brands-github: `fontawesome/brands/github`
- :fontawesome-brands-github-alt: `fontawesome/brands/github-alt`
- :fontawesome-brands-gitlab: `fontawesome/brands/gitlab`
- :fontawesome-brands-gitkraken: `fontawesome/brands/gitkraken`
- :fontawesome-brands-bitbucket: `fontawesome/brands/bitbucket`
- :fontawesome-solid-trash: `fontawesome/solid/trash`
[icon search]: ../reference/icons-emojis.md#search
#### Code actions
2023-09-14 19:09:18 +02:00
<!-- md:version 9.0.0 -->
<!-- md:feature -->
2023-02-18 11:15:25 +01:00
If the [repository URL] points to a valid [GitHub], [GitLab] or [Bitbucket]
repository, [MkDocs] provides a setting called [`edit_uri`][edit_uri], which
resolves to the subfolder where your documentation is hosted.
2023-02-18 11:15:25 +01:00
If your default branch is called `main`, change the setting to:
``` yaml
edit_uri: edit/main/docs/
2023-02-18 11:15:25 +01:00
```
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):
=== ":material-file-edit-outline: Edit this page"
``` yaml
theme:
features:
- content.action.edit
```
2023-02-18 11:15:25 +01:00
=== ":material-file-eye-outline: View source of this page"
``` yaml
theme:
features:
- content.action.view
```
The icon of the edit and view buttons can be changed with the following lines:
2022-09-11 19:25:40 +02:00
``` yaml
theme:
icon:
edit: material/pencil # (1)!
view: material/eye
2022-09-11 19:25:40 +02:00
```
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:
<div class="mdx-iconsearch" data-mdx-component="iconsearch">
<input class="md-input md-input--stretch mdx-iconsearch__input" placeholder="Search icon" data-mdx-component="iconsearch-query" value="material pencil" />
2022-09-11 19:25:40 +02:00
<div class="mdx-iconsearch-result" data-mdx-component="iconsearch-result" data-mdx-mode="file">
<div class="mdx-iconsearch-result__meta"></div>
<ol class="mdx-iconsearch-result__list"></ol>
</div>
</div>
[repository URL]: #repository
2021-10-10 22:32:32 +02:00
[GitHub]: https://github.com/
[GitLab]: https://about.gitlab.com/
[Bitbucket]: https://bitbucket.org/
2023-02-18 11:15:25 +01:00
[MkDocs]: https://www.mkdocs.org
[edit_uri]: https://www.mkdocs.org/user-guide/configuration/#edit_uri
2022-06-24 14:38:01 +02:00
### Revisioning
2022-06-24 14:38:01 +02:00
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.
2022-06-24 14:38:01 +02:00
[date of last update and creation]: #document-dates
[contributors]: #document-contributors
[authors]: #document-authors
#### Document dates
2023-09-14 19:09:18 +02:00
<!-- md:version 4.6.0 -->
<!-- md:plugin [git-revision-date-localized] -->
2022-06-24 14:38:01 +02:00
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`:
```
2022-06-24 14:38:01 +02:00
pip install mkdocs-git-revision-date-localized-plugin
```
2021-10-10 22:32:32 +02:00
Then, add the following lines to `mkdocs.yml`:
``` yaml
plugins:
2022-06-24 14:38:01 +02:00
- git-revision-date-localized:
enable_creation_date: true
```
2021-10-10 22:32:32 +02:00
The following configuration options are supported:
2023-09-14 19:09:18 +02:00
<!-- md:option git-revision-date-localized.enabled -->
2023-09-14 19:09:18 +02:00
: <!-- md:default `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]:
``` yaml
plugins:
- git-revision-date-localized:
enabled: !ENV [CI, false]
```
2023-09-14 19:09:18 +02:00
<!-- md:option git-revision-date-localized.type -->
2023-09-14 19:09:18 +02:00
: <!-- md:default `date` --> The format of the date to be
2022-06-24 14:38:01 +02:00
displayed. Valid values are `date`, `datetime`, `iso_date`, `iso_datetime`
and `timeago`:
``` yaml
plugins:
2022-06-24 14:38:01 +02:00
- git-revision-date-localized:
type: date
```
2023-09-14 19:09:18 +02:00
<!-- md:option git-revision-date-localized.enable_creation_date -->
2022-06-24 14:38:01 +02:00
2023-09-14 19:09:18 +02:00
: <!-- md:default `false` --> Enables the display of the
2022-06-24 14:38:01 +02:00
creation date of the file associated with the page next to the last updated
date at the bottom of the page:
``` yaml
plugins:
- git-revision-date-localized:
enable_creation_date: true
```
2023-09-18 20:08:55 +02:00
!!! note "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].
2023-09-15 04:56:00 +02:00
2023-09-14 19:09:18 +02:00
<!-- md:option git-revision-date-localized.fallback_to_build_date -->
2022-06-24 14:38:01 +02:00
2023-09-14 19:09:18 +02:00
: <!-- md:default `false` --> Enables falling back to
2022-06-24 14:38:01 +02:00
the time when `mkdocs build` was executed. Can be used as a fallback when
the build is performed outside of a git repository:
``` yaml
plugins:
- git-revision-date-localized:
fallback_to_build_date: true
```
2021-10-10 22:32:32 +02:00
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.
2022-06-24 14:38:01 +02:00
[git-revision-date-localized]: https://github.com/timvink/mkdocs-git-revision-date-localized-plugin
2022-08-21 19:10:19 +02:00
#### Document contributors
2023-12-07 11:56:18 +01:00
<!-- md:version 9.5.0 -->
2023-09-14 19:09:18 +02:00
<!-- md:plugin [git-committers] -->
<!-- md:flag experimental -->
2022-06-24 14:38:01 +02:00
The [git-committers][^2] 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`:
2022-06-24 14:38:01 +02:00
[^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.
```
2022-06-24 14:38:01 +02:00
pip install mkdocs-git-committers-plugin-2
```
2022-06-24 14:38:01 +02:00
Then, add the following lines to `mkdocs.yml`:
``` yaml
plugins:
2022-06-24 14:38:01 +02:00
- git-committers:
repository: squidfunk/mkdocs-material
2022-08-31 22:57:27 +02:00
branch: main
```
2021-10-10 22:32:32 +02:00
The following configuration options are supported:
2023-09-14 19:09:18 +02:00
<!-- md:option git-committers.enabled -->
2023-09-14 19:09:18 +02:00
: <!-- md:default `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]:
``` yaml
plugins:
- git-committers:
enabled: !ENV [CI, false]
```
2023-09-14 19:09:18 +02:00
<!-- md:option git-committers.repository -->
2023-09-14 19:09:18 +02:00
: <!-- md:default none --> <!-- md:flag required -->
2022-06-24 14:38:01 +02:00
This property must be set to the slug of the repository that contains your
documentation. The slug must follow the pattern `<username>/<repository>`:
``` yaml
plugins:
2022-06-24 14:38:01 +02:00
- git-committers:
repository: squidfunk/mkdocs-material
```
2023-09-14 19:09:18 +02:00
<!-- md:option git-committers.branch -->
2023-09-14 19:09:18 +02:00
: <!-- md:default `master` --> This property should be set to
2022-08-31 22:57:27 +02:00
the branch of the repository from which to retrieve the contributors. To use the `main` branch:
``` yaml
plugins:
2022-06-24 14:38:01 +02:00
- git-committers:
2022-08-31 22:57:27 +02:00
branch: main
```
2021-10-10 22:32:32 +02:00
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.
2022-06-24 14:38:01 +02:00
[Insiders]: ../insiders/index.md
[git-committers]: https://github.com/ojacques/mkdocs-git-committers-plugin-2
[environment variable]: https://www.mkdocs.org/user-guide/configuration/#environment-variables
2022-06-24 14:38:01 +02:00
[rate limits]: https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting
2022-10-02 16:36:47 +02:00
#### Document authors
2022-06-24 14:38:01 +02:00
2023-12-07 11:56:18 +01:00
<!-- md:version 9.5.0 -->
2023-09-14 19:09:18 +02:00
<!-- md:plugin [git-authors] -->
<!-- md:flag experimental -->
2022-06-24 14:38:01 +02:00
2023-06-15 16:45:44 +02:00
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.
2023-12-07 11:56:18 +01:00
Material for MkDocs offers deep integration for [git-authors]. This means the
[customized overrides](https://timvink.github.io/mkdocs-git-authors-plugin/usage.html#mkdocs-material-theme)
are not necessary, and additional styling (such as nice icons) are added.
Simply install it with `pip`:
2022-06-24 14:38:01 +02:00
```
pip install mkdocs-git-authors-plugin
```
Then, add the following lines to `mkdocs.yml`:
``` yaml
plugins:
- git-authors
```
[git-authors]: https://github.com/timvink/mkdocs-git-authors-plugin/