Skip to content

Commit 6713712

Browse files
authored
remove repo_type and make repo_name intuitive (#260)
resolves #259
1 parent 99befd6 commit 6713712

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112
"site_url": "https://jbms.github.io/sphinx-immaterial/",
113113
"repo_url": "https://github.com/jbms/sphinx-immaterial/",
114114
"repo_name": "Sphinx-Immaterial",
115-
"repo_type": "github",
116115
"edit_uri": "blob/main/docs",
117116
"globaltoc_collapse": True,
118117
"features": [

docs/customization.rst

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,27 @@ Configuration Options
176176

177177
.. themeconf:: repo_url
178178

179-
Set the repo url for the link to appear.
179+
The link to the repository will be rendered next to the search bar on large screens and as
180+
part of the main navigation drawer on smaller screen sizes. Additionally, for public
181+
repositories hosted on `GitHub <https://github.com>`_ or `GitLab
182+
<https://about.gitlab.com/>`_, the number of stars and forks is automatically requested and
183+
rendered.
184+
185+
GitHub repositories also include the tag of the latest release. Unfortunately, GitHub
186+
only provides `an API endpoint to obtain the latest release
187+
<https://docs.github.com/en/rest/releases/releases#get-the-latest-release>`_ - not the
188+
latest tag. Thus, make sure to create a release (not pre-release) for the latest tag you
189+
want to display next to the number of stars and forks.
180190

181191
.. themeconf:: repo_name
182192

183-
The name of the repo. If must be set if repo_url is set.
193+
The name of the repository. If :themeconf:`repo_url` is set, then the repository's name
194+
will be extracted from the given URL. Optionally, this can be set to customize the
195+
repository name.
184196

185-
.. themeconf:: repo_type
186-
187-
Must be one of github, gitlab or bitbucket.
197+
.. warning::
198+
If the :themeconf:`repo_url` does not use a ``github``, ``gitlab``, or ``bitbucket``
199+
domain, then this option must be set explicitly.
188200

189201
.. themeconf:: icon
190202

sphinx_immaterial/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Sphinx-Immaterial theme."""
22

33
import os
4+
import re
5+
from urllib.parse import urlparse
46
from typing import cast, List, Type, Dict, Mapping, Optional
57

68
import docutils.nodes
@@ -245,6 +247,20 @@ def _config_inited(
245247
DEFAULT_THEME_OPTIONS, config["html_theme_options"]
246248
)
247249

250+
theme_options: dict = config["html_theme_options"]
251+
repo_url: Optional[str] = theme_options.get("repo_url", None)
252+
if not theme_options.get("repo_name", None) and repo_url:
253+
# auto-extract repo_name from repo_url
254+
url = urlparse(repo_url)
255+
if re.search("github|gitlab|bitbucket", url.netloc) is None:
256+
raise AttributeError(
257+
"'repo_url' does not use a github, gitlab, or bitbucket domain, so"
258+
" the `repo_name` must be set explicitly."
259+
)
260+
config["html_theme_options"]["repo_name"] = url.path.split("/")[2].rstrip(
261+
".git"
262+
)
263+
248264

249265
def setup(app: Sphinx):
250266
app.connect("config-inited", _config_inited)

sphinx_immaterial/theme.conf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ consent =
4848
repo_url =
4949
# The name of the repo. If must be set if repo_url is set
5050
repo_name =
51-
# Must be one of github, gitlab or bitbucket
52-
repo_type = github
5351
# url segment that is concatenated with repo_url to point readers to the document's
5452
# source file. This is typically in the form of 'blob/<branch name>/<docs source folder>'.
5553
edit_uri =

0 commit comments

Comments
 (0)