1414
1515
1616def return_html_theme_options (app : Sphinx ) -> dict [str , object ]:
17- return {
17+ theme_options = {
1818 "navbar_align" : "content" ,
1919 "header_links_before_dropdown" : 5 ,
2020 "icon_links" : [
@@ -28,20 +28,33 @@ def return_html_theme_options(app: Sphinx) -> dict[str, object]:
2828 # https://pydata-sphinx-theme.readthedocs.io/en/stable/user_guide/source-buttons.html#add-an-edit-button
2929 "use_edit_page_button" : True ,
3030 "collapse_navigation" : True ,
31- # Enable version switcher
32- "switcher" : {
33- "json_url" : (
34- f"https://{ html_context ['github_user' ]} .github.io/"
35- f"{ html_context ['github_repo' ]} /versions.json"
36- ), # URL to JSON file, hardcoded for now
37- "version_match" : app .config .release ,
38- },
39- "navbar_end" : ["theme-switcher" , "navbar-icon-links" , "version-switcher" ],
4031 "logo" : {
4132 "text" : "Eclipse S-CORE" ,
4233 },
4334 }
4435
36+ # Enable version switcher if github_user and github_repo are provided via CLI
37+ if (
38+ app .config .html_context .get ("github_user" ) != "dummy"
39+ and app .config .html_context .get ("github_repo" ) != "dummy"
40+ ):
41+ theme_options ["switcher" ] = {
42+ "json_url" : (
43+ f"https://{ app .config .html_context ['github_user' ]} .github.io/"
44+ f"{ app .config .html_context ['github_repo' ]} /versions.json"
45+ ), # URL to JSON file, hardcoded for now
46+ "version_match" : app .config .release ,
47+ }
48+ theme_options ["navbar_end" ] = [
49+ "theme-switcher" ,
50+ "navbar-icon-links" ,
51+ "version-switcher" ,
52+ ]
53+ else :
54+ theme_options ["navbar_end" ] = ["theme-switcher" , "navbar-icon-links" ]
55+
56+ return theme_options
57+
4558
4659html_theme = "pydata_sphinx_theme" # "alabaster"
4760html_static_path = ["src/assets" , "_assets" ]
@@ -54,10 +67,16 @@ def return_html_theme_options(app: Sphinx) -> dict[str, object]:
5467# html_logo = "_assets/S-CORE_Logo_white.svg"
5568
5669
57- html_context = {
58- # "github_url": "https://github.com", # or your GitHub Enterprise site
59- "github_user" : "eclipse-score" ,
60- "github_repo" : "score" ,
61- "github_version" : "main" ,
62- "doc_path" : "docs" ,
63- }
70+ def return_html_context (app : Sphinx ) -> dict [str , str ]:
71+ if not hasattr (app .config , "html_context" ) or (
72+ not app .config .html_context .get ("github_user" )
73+ and not app .config .html_context .get ("github_repo" )
74+ ):
75+ return {
76+ # still required for use_edit_page_button and other elements except version switcher
77+ "github_user" : "dummy" ,
78+ "github_repo" : "dummy" ,
79+ "github_version" : "main" ,
80+ "doc_path" : "docs" ,
81+ }
82+ return app .config .html_context
0 commit comments