51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
# import json
|
|
from pathlib import Path
|
|
|
|
from sphinx.util import logging
|
|
# from docutils import nodes
|
|
|
|
__version__ = "0.1"
|
|
|
|
def add_static_sources(app):
|
|
static_path = Path(__file__).parent / "static"
|
|
app.config.html_static_path.append(static_path.as_posix())
|
|
|
|
|
|
def remove_buttons(app, pagename, _templatename, context, _doctree):
|
|
if not pagename.startswith("U0"):
|
|
# not one of the units, don't do anything
|
|
return
|
|
|
|
is_engish = pagename.endswith(".en")
|
|
|
|
buttons = context["header_buttons"]
|
|
|
|
keep = []
|
|
for button in buttons:
|
|
try:
|
|
if button["tooltip"] == "Start presenting":
|
|
keep.append(button)
|
|
except Exception as _e:
|
|
pass
|
|
|
|
keep.append({
|
|
"type": "javascript",
|
|
"javascript": "switchLanguage()",
|
|
"tooltip": "Deutsch" if is_engish else "English",
|
|
"icon": "fas fa-language",
|
|
})
|
|
app.add_js_file("switch-language.js")
|
|
|
|
context["header_buttons"] = keep
|
|
|
|
|
|
def setup(app):
|
|
app.connect("builder-inited", add_static_sources)
|
|
app.connect("html-page-context", remove_buttons, priority=9999)
|
|
|
|
return {
|
|
"version": __version__,
|
|
"parallel_read_safe": True,
|
|
"parallel_write_safe": True,
|
|
}
|