From 455b3d3c3145254228ce31d73d8964d13550527c Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Sun, 20 Sep 2020 19:38:33 +0200 Subject: Add a :user: role in Sphinx This change adds a role that links to the GitHub user Sponsors page. If that page is not set up, it'll redirect to the GitHub user profile page instead: Links to https://github.com/sponsors/{{ username }} open as GitHub Sponsors page if the target `username` has it enabled and redirect to https://github.com/{{ username }} if it's disabled. --- docs/conf.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'docs/conf.py') diff --git a/docs/conf.py b/docs/conf.py index 673b6ba5..d5111391 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -10,9 +10,18 @@ import os cwd=os.path.join(os.path.dirname(__file__), os.path.pardir), ) +# -- Project information ----------------------------------------------------- + +github_url = 'https://github.com' +github_sponsors_url = f'{github_url}/sponsors' + # -- General configuration -- -extensions = ['jaraco.packaging.sphinx', 'rst.linker'] +extensions = [ + 'sphinx.ext.extlinks', # allows to create custom roles easily + 'jaraco.packaging.sphinx', + 'rst.linker', +] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] @@ -27,6 +36,11 @@ exclude_trees = [] # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' +# -- Options for extlinks extension --------------------------------------- +extlinks = { + 'user': (f'{github_sponsors_url}/%s', '@'), # noqa: WPS323 +} + # -- Options for HTML output -- # The theme to use for HTML and HTML Help pages. Major themes that come with -- cgit v1.2.1