Skip to content

Commit bd8e6cb

Browse files
committed
add versions
1 parent 89db940 commit bd8e6cb

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

docs/source/_templates/versioning.html

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/source/conf.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os
1010
import sys
1111
from pathlib import Path
12+
from importlib.metadata import version
1213

1314
conf_dir = os.path.dirname(os.path.abspath(__file__)) # noqa: PTH100, PTH120
1415

@@ -83,7 +84,9 @@
8384

8485
html_theme = "pydata_sphinx_theme"
8586
html_static_path = ["../_static"]
87+
version = version("autointent").replace("dev", "") # may differ
8688

89+
BASE_URL = "https://deeppavlov.github.io/AutoIntent"
8790
html_theme_options = {
8891
"logo": {
8992
"text": "AutoIntent",
@@ -104,6 +107,11 @@
104107
"type": "local",
105108
},
106109
],
110+
"switcher": {
111+
"json_url": f"{BASE_URL}/_static/versions.json",
112+
"version_match": version,
113+
},
114+
"navbar_start": ["navbar-logo", "version-switcher"],
107115
"show_toc_level": 3,
108116
}
109117

@@ -133,11 +141,11 @@
133141
"user_guides/*": "_static/square-white.svg",
134142
}
135143

136-
html_sidebars = {
137-
'**': [
138-
'versioning.html',
139-
],
140-
}
144+
# html_sidebars = {
145+
# '**': [
146+
# 'versioning.html',
147+
# ],
148+
# }
141149

142150
mathjax_path = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"
143151

@@ -156,7 +164,7 @@
156164

157165
repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', "..")) # if conf.py is in docs/
158166
def setup(app) -> None: # noqa: ANN001
159-
generate_versions_json(app, repo_root)
167+
generate_versions_json(app, repo_root, BASE_URL)
160168
# versions = get_sorted_versions()
161169
# with open('docs/source/_static/versions.json', 'w') as f:
162170
# json.dump(versions, f, indent=4)

docs/source/docs_utils/versions_generator.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import subprocess
1010

1111

12-
def get_sorted_versions(repo_root):
12+
def get_sorted_versions(repo_root, base_url):
1313
# Get the git repository root
1414
tags_output = subprocess.check_output(['git', '-C', repo_root, 'tag'], text=True).strip().split('\n')
1515
# Change to the repository root
@@ -34,13 +34,14 @@ def version_key(tag):
3434
versions.append({
3535
"name": f"{sorted_tags[0]} (stable)",
3636
"version": sorted_tags[0].lstrip('v'),
37-
"url": f"/{sorted_tags[0].lstrip('v')}/"
37+
"url": f"{base_url}/{sorted_tags[0].lstrip('v')}/",
38+
"preferred": True,
3839
})
3940

4041
for tag in sorted_tags[1:]:
4142
versions.append({
4243
"version": tag.lstrip('v'),
43-
"url": f"/{tag.lstrip('v')}/"
44+
"url": f"{base_url}/{tag.lstrip('v')}/"
4445
})
4546

4647
# Get branches
@@ -55,13 +56,13 @@ def version_key(tag):
5556
for branch in dev_branches:
5657
versions.append({
5758
"version": f"{branch} (dev)",
58-
"url": f"/{branch}/"
59+
"url": f"{base_url}/{branch}/"
5960
})
6061

6162
return versions
6263

6364

64-
def generate_versions_json(app, repo_root):
65+
def generate_versions_json(app, repo_root, base_url):
6566
"""
6667
Sphinx extension to generate versions.json during documentation build.
6768
"""

0 commit comments

Comments
 (0)