From 6094558507a7ca1c6620f1ffbd22be5646b0aaa6 Mon Sep 17 00:00:00 2001 From: Alex Hadley Date: Sat, 24 Aug 2024 18:21:00 -0400 Subject: [PATCH] Add custom view URL and GitHub icon to Sphinx --- docs/conf.py | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index f0fb5d1..f17d607 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,20 +15,42 @@ "jupyter_sphinx", ] +# Determine the git version to use +import subprocess + +def run_command(*args: str) -> str: + return subprocess.check_output(args).decode().strip() + +git_version = run_command("git", "rev-parse", "--abbrev-ref", "HEAD") +if git_version == "HEAD": + git_version = run_command("git", "describe", "--exact-match", "--tags") + +# Construct GitHub links +git_base_url = "https://github.com/PainterQubits/datalogs" +git_view_link = ( + f"{git_base_url}/blob/{git_version}/docs/{{filename}}?plain=1" +) +git_repo_link = f"https://github.com/PainterQubits/datalogs/tree/{git_version}" + # HTML output options html_theme = "furo" html_static_path = ["_static"] -html_context = { - "display_github": True, - "github_user": "PainterQubits", - "github_repo": "datalogs", - "github_version": "main/docs/", +html_theme_options = { + "source_view_link": git_view_link, + # From https://pradyunsg.me/furo/customisation/footer/#using-embedded-svgs + "footer_icons": [ + { + "name": "GitHub", + "url": git_repo_link, + "html": """ + + + + """, + "class": "", + }, + ], } -# html_theme_options = { -# "source_repository": "https://github.com/PainterQubits/datalogs", -# "source_branch": "main", -# "source_directory": "docs", -# } # MyST options myst_heading_anchors = 3