Skip to content

Commit 95223a4

Browse files
committed
🧱 local switcher.json is now exported into build dir
1 parent 8330296 commit 95223a4

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

docs/conf.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919

2020
DEFAULT_SWITCHER_URL = f"https://libhal.github.io/api/{LIBRARY_NAME}/switcher.json"
2121

22-
if os.environ.get('LIBHAL_LOCAL_BUILD'):
23-
switcher_path = Path('_static') / 'switcher.json'
24-
switcher_path.write_text(
25-
json.dumps([{"version": API_VERSION, "url": "."}]))
26-
switcher_url = "_static/switcher.json"
22+
LOCAL_BUILD = os.environ.get('LIBHAL_LOCAL_BUILD')
23+
24+
if LOCAL_BUILD:
25+
switcher_url = "switcher.json"
2726
else:
2827
switcher_url = DEFAULT_SWITCHER_URL
2928

@@ -44,8 +43,16 @@
4443
extensions = ["breathe", "myst_parser"]
4544

4645

46+
def write_local_switcher(app, exception):
47+
if LOCAL_BUILD and exception is None:
48+
outdir = Path(app.outdir)
49+
(outdir / 'switcher.json').write_text(
50+
json.dumps([{"version": API_VERSION, "url": "."}]))
51+
52+
4753
def setup(app: Sphinx):
4854
app.add_css_file("extra.css")
55+
app.connect("build-finished", write_local_switcher)
4956

5057

5158
html_css_files = [

0 commit comments

Comments
 (0)