mirror of
https://github.com/mkdocs/mkdocs.git
synced 2026-03-27 18:08:31 +07:00
Add support for GitLab repositories (#1435)
Note that the icons in the themes will not show up until FontAwesome is updated to at least version 4.6 and/or an up-to-date version of the upstream readthedocs css is imported. This commit also fixes a slight documentation error regarding the default value of `repo_name` and removes some tautological tests.
This commit is contained in:
committed by
Waylan Limberg
parent
1c80f6d663
commit
71ebf353e6
@@ -35,7 +35,8 @@ URL to the generated HTML header.
|
|||||||
|
|
||||||
### repo_url
|
### repo_url
|
||||||
|
|
||||||
When set, provides a link to your GitHub or Bitbucket repository on each page.
|
When set, provides a link to your repository (GitHub, Bitbucket, GitLab, ...)
|
||||||
|
on each page.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
repo_url: https://github.com/example/repository/
|
repo_url: https://github.com/example/repository/
|
||||||
@@ -45,10 +46,10 @@ repo_url: https://github.com/example/repository/
|
|||||||
|
|
||||||
### repo_name
|
### repo_name
|
||||||
|
|
||||||
When set, provides a link to your GitHub or Bitbucket repository on each page.
|
When set, provides the name for the link to your repository on each page.
|
||||||
|
|
||||||
**default**: `'GitHub'` or `'Bitbucket'` if the `repo_url` matches those
|
**default**: `'GitHub'`, `'Bitbucket'` or `'GitLab'` if the `repo_url` matches
|
||||||
domains, otherwise `null`
|
those domains, otherwise the hostname from the `repo_url`.
|
||||||
|
|
||||||
### edit_uri
|
### edit_uri
|
||||||
|
|
||||||
@@ -86,14 +87,14 @@ edit_uri: root/path/docs/
|
|||||||
```
|
```
|
||||||
|
|
||||||
!!! note
|
!!! note
|
||||||
On a few known hosts (specifically GitHub and Bitbucket), the `edit_uri` is
|
On a few known hosts (specifically GitHub, Bitbucket and GitLab), the
|
||||||
derived from the 'repo_url' and does not need to be set manually. Simply
|
`edit_uri` is derived from the 'repo_url' and does not need to be set
|
||||||
defining a `repo_url` will automatically populate the `edit_uri` config
|
manually. Simply defining a `repo_url` will automatically populate the
|
||||||
setting.
|
`edit_uri` configs setting.
|
||||||
|
|
||||||
For example, for a GitHub-hosted repository, the `edit_uri` would be
|
For example, for a GitHub- or GitLab-hosted repository, the `edit_uri`
|
||||||
automatically set as `edit/master/docs/` (Note the `edit` path and `master`
|
would be automatically set as `edit/master/docs/` (Note the `edit` path
|
||||||
branch).
|
and `master` branch).
|
||||||
|
|
||||||
For a Bitbucket-hosted repository, the equivalent `edit_uri` would be
|
For a Bitbucket-hosted repository, the equivalent `edit_uri` would be
|
||||||
automatically set as `src/default/docs/` (note the `src` path and `default`
|
automatically set as `src/default/docs/` (note the `src` path and `default`
|
||||||
@@ -105,15 +106,16 @@ edit_uri: root/path/docs/
|
|||||||
string to disable the automatic setting.
|
string to disable the automatic setting.
|
||||||
|
|
||||||
!!! warning
|
!!! warning
|
||||||
On GitHub, the default "edit" path (`edit/master/docs/`) opens the page in
|
On GitHub and GitLab, the default "edit" path (`edit/master/docs/`) opens
|
||||||
the online GitHub editor. This functionality requires that the user have and
|
the page in the online editor. This functionality requires that the user
|
||||||
be logged in to a GitHub account. Otherwise, the user will be redirected to
|
have and be logged in to a GitHub/GitLab account. Otherwise, the user will
|
||||||
a login/signup page. Alternatively, use the "blob" path
|
be redirected to a login/signup page. Alternatively, use the "blob" path
|
||||||
(`blob/master/docs/`) to open a read-only view, which supports anonymous
|
(`blob/master/docs/`) to open a read-only view, which supports anonymous
|
||||||
access.
|
access.
|
||||||
|
|
||||||
**default**: `edit/master/docs/` or `src/default/docs/` for GitHub or Bitbucket
|
**default**: `edit/master/docs/` for GitHub and GitLab repos or
|
||||||
repos, respectively, if `repo_url` matches those domains, otherwise `null`
|
`src/default/docs/` for a Bitbucket repo, if `repo_url` matches those domains,
|
||||||
|
otherwise `null`
|
||||||
|
|
||||||
### site_description
|
### site_description
|
||||||
|
|
||||||
|
|||||||
@@ -260,12 +260,14 @@ class RepoURL(URL):
|
|||||||
config['repo_name'] = 'GitHub'
|
config['repo_name'] = 'GitHub'
|
||||||
elif repo_host == 'bitbucket.org':
|
elif repo_host == 'bitbucket.org':
|
||||||
config['repo_name'] = 'Bitbucket'
|
config['repo_name'] = 'Bitbucket'
|
||||||
|
elif repo_host == 'gitlab.com':
|
||||||
|
config['repo_name'] = 'GitLab'
|
||||||
else:
|
else:
|
||||||
config['repo_name'] = repo_host.split('.')[0].title()
|
config['repo_name'] = repo_host.split('.')[0].title()
|
||||||
|
|
||||||
# derive edit_uri from repo_name if unset
|
# derive edit_uri from repo_name if unset
|
||||||
if config['repo_url'] is not None and edit_uri is None:
|
if config['repo_url'] is not None and edit_uri is None:
|
||||||
if repo_host == 'github.com':
|
if repo_host == 'github.com' or repo_host == 'gitlab.com':
|
||||||
edit_uri = 'edit/master/docs/'
|
edit_uri = 'edit/master/docs/'
|
||||||
elif repo_host == 'bitbucket.org':
|
elif repo_host == 'bitbucket.org':
|
||||||
edit_uri = 'src/default/docs/'
|
edit_uri = 'src/default/docs/'
|
||||||
|
|||||||
@@ -68,7 +68,8 @@ DEFAULT_SCHEMA = (
|
|||||||
|
|
||||||
# A name to use for the link to the project source repo.
|
# A name to use for the link to the project source repo.
|
||||||
# Default, If repo_url is unset then None, otherwise
|
# Default, If repo_url is unset then None, otherwise
|
||||||
# "GitHub" or "Bitbucket" for known url or Hostname for unknown urls.
|
# "GitHub", "Bitbucket" or "GitLab" for known url or Hostname
|
||||||
|
# for unknown urls.
|
||||||
('repo_name', config_options.Type(utils.string_types)),
|
('repo_name', config_options.Type(utils.string_types)),
|
||||||
|
|
||||||
# Specify a URI to the docs dir in the project source repo, relative to the
|
# Specify a URI to the docs dir in the project source repo, relative to the
|
||||||
|
|||||||
@@ -172,7 +172,6 @@ class RepoURLTest(unittest.TestCase):
|
|||||||
option = config_options.RepoURL()
|
option = config_options.RepoURL()
|
||||||
config = {'repo_url': "https://github.com/mkdocs/mkdocs"}
|
config = {'repo_url': "https://github.com/mkdocs/mkdocs"}
|
||||||
option.post_validation(config, 'repo_url')
|
option.post_validation(config, 'repo_url')
|
||||||
self.assertEqual(config['repo_url'], config['repo_url'])
|
|
||||||
self.assertEqual(config['repo_name'], "GitHub")
|
self.assertEqual(config['repo_name'], "GitHub")
|
||||||
|
|
||||||
def test_repo_name_bitbucket(self):
|
def test_repo_name_bitbucket(self):
|
||||||
@@ -180,15 +179,20 @@ class RepoURLTest(unittest.TestCase):
|
|||||||
option = config_options.RepoURL()
|
option = config_options.RepoURL()
|
||||||
config = {'repo_url': "https://bitbucket.org/gutworth/six/"}
|
config = {'repo_url': "https://bitbucket.org/gutworth/six/"}
|
||||||
option.post_validation(config, 'repo_url')
|
option.post_validation(config, 'repo_url')
|
||||||
self.assertEqual(config['repo_url'], config['repo_url'])
|
|
||||||
self.assertEqual(config['repo_name'], "Bitbucket")
|
self.assertEqual(config['repo_name'], "Bitbucket")
|
||||||
|
|
||||||
|
def test_repo_name_gitlab(self):
|
||||||
|
|
||||||
|
option = config_options.RepoURL()
|
||||||
|
config = {'repo_url': "https://gitlab.com/gitlab-org/gitlab-ce/"}
|
||||||
|
option.post_validation(config, 'repo_url')
|
||||||
|
self.assertEqual(config['repo_name'], "GitLab")
|
||||||
|
|
||||||
def test_repo_name_custom(self):
|
def test_repo_name_custom(self):
|
||||||
|
|
||||||
option = config_options.RepoURL()
|
option = config_options.RepoURL()
|
||||||
config = {'repo_url': "https://launchpad.net/python-tuskarclient"}
|
config = {'repo_url': "https://launchpad.net/python-tuskarclient"}
|
||||||
option.post_validation(config, 'repo_url')
|
option.post_validation(config, 'repo_url')
|
||||||
self.assertEqual(config['repo_url'], config['repo_url'])
|
|
||||||
self.assertEqual(config['repo_name'], "Launchpad")
|
self.assertEqual(config['repo_name'], "Launchpad")
|
||||||
|
|
||||||
def test_edit_uri_github(self):
|
def test_edit_uri_github(self):
|
||||||
@@ -205,6 +209,13 @@ class RepoURLTest(unittest.TestCase):
|
|||||||
option.post_validation(config, 'repo_url')
|
option.post_validation(config, 'repo_url')
|
||||||
self.assertEqual(config['edit_uri'], 'src/default/docs/')
|
self.assertEqual(config['edit_uri'], 'src/default/docs/')
|
||||||
|
|
||||||
|
def test_edit_uri_gitlab(self):
|
||||||
|
|
||||||
|
option = config_options.RepoURL()
|
||||||
|
config = {'repo_url': "https://gitlab.com/gitlab-org/gitlab-ce/"}
|
||||||
|
option.post_validation(config, 'repo_url')
|
||||||
|
self.assertEqual(config['edit_uri'], 'edit/master/docs/')
|
||||||
|
|
||||||
def test_edit_uri_custom(self):
|
def test_edit_uri_custom(self):
|
||||||
|
|
||||||
option = config_options.RepoURL()
|
option = config_options.RepoURL()
|
||||||
|
|||||||
@@ -78,6 +78,8 @@
|
|||||||
<i class="fa fa-github"></i> Edit on {{ config.repo_name }}
|
<i class="fa fa-github"></i> Edit on {{ config.repo_name }}
|
||||||
{%- elif config.repo_name == 'Bitbucket' -%}
|
{%- elif config.repo_name == 'Bitbucket' -%}
|
||||||
<i class="fa fa-bitbucket"></i> Edit on {{ config.repo_name }}
|
<i class="fa fa-bitbucket"></i> Edit on {{ config.repo_name }}
|
||||||
|
{%- elif config.repo_name == 'GitLab' -%}
|
||||||
|
<i class="fa fa-gitlab"></i> Edit on {{ config.repo_name }}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
Edit on {{ config.repo_name }}
|
Edit on {{ config.repo_name }}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
@@ -90,6 +92,8 @@
|
|||||||
<i class="fa fa-github"></i> {{ config.repo_name }}
|
<i class="fa fa-github"></i> {{ config.repo_name }}
|
||||||
{%- elif config.repo_name == 'Bitbucket' -%}
|
{%- elif config.repo_name == 'Bitbucket' -%}
|
||||||
<i class="fa fa-bitbucket"></i> {{ config.repo_name }}
|
<i class="fa fa-bitbucket"></i> {{ config.repo_name }}
|
||||||
|
{%- elif config.repo_name == 'GitLab' -%}
|
||||||
|
<i class="fa fa-gitlab"></i> {{ config.repo_name }}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{{ config.repo_name }}
|
{{ config.repo_name }}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
class="icon icon-github"
|
class="icon icon-github"
|
||||||
{%- elif config.repo_name|lower == 'bitbucket' %}
|
{%- elif config.repo_name|lower == 'bitbucket' %}
|
||||||
class="icon icon-bitbucket"
|
class="icon icon-bitbucket"
|
||||||
|
{%- elif config.repo_name|lower == 'gitlab' %}
|
||||||
|
class="icon icon-gitlab"
|
||||||
{% endif %}> Edit on {{ config.repo_name }}</a>
|
{% endif %}> Edit on {{ config.repo_name }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{%- endblock %}
|
{%- endblock %}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
<a href="{{ config.repo_url }}" class="fa fa-github" style="float: left; color: #fcfcfc"> GitHub</a>
|
<a href="{{ config.repo_url }}" class="fa fa-github" style="float: left; color: #fcfcfc"> GitHub</a>
|
||||||
{% elif config.repo_name == 'Bitbucket' %}
|
{% elif config.repo_name == 'Bitbucket' %}
|
||||||
<a href="{{ config.repo_url }}" class="icon icon-bitbucket" style="float: left; color: #fcfcfc"> BitBucket</a>
|
<a href="{{ config.repo_url }}" class="icon icon-bitbucket" style="float: left; color: #fcfcfc"> BitBucket</a>
|
||||||
|
{% elif config.repo_name == 'GitLab' %}
|
||||||
|
<a href="{{ config.repo_url }}" class="icon icon-gitlab" style="float: left; color: #fcfcfc"> GitLab</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if page.previous_page %}
|
{% if page.previous_page %}
|
||||||
<span><a href="{{ page.previous_page.url }}" style="color: #fcfcfc;">« Previous</a></span>
|
<span><a href="{{ page.previous_page.url }}" style="color: #fcfcfc;">« Previous</a></span>
|
||||||
|
|||||||
Reference in New Issue
Block a user