Skip to content

Commit c67a885

Browse files
authored
DOC - Enable viewing dev and stable versions of package documentation (#206)
1 parent 261fee0 commit c67a885

File tree

5 files changed

+97
-2
lines changed

5 files changed

+97
-2
lines changed

.circleci/config.yml

+12
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,21 @@ jobs:
7878
chmod og= ~/.ssh/config
7979
cd doc;
8080
pip install ghp-import;
81+
make add-stable-doc
8182
make install
8283
fi
8384
85+
# Add stable documentation
86+
- run:
87+
name: stable_doc
88+
command: |
89+
set -e
90+
mkdir -p ~/.ssh
91+
echo -e "Host *\nStrictHostKeyChecking no" > ~/.ssh/config
92+
chmod og= ~/.ssh/config
93+
cd doc;
94+
make add-stable-doc
95+
8496
# Save the outputs
8597
- store_artifacts:
8698
path: doc/_build/html/

doc/Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ BUILDDIR = _build
99

1010
GITHUB_PAGES_BRANCH = gh-pages
1111
OUTPUTDIR = _build/html
12+
STABLE_DOC_DIR = stable
1213

1314
# User-friendly check for sphinx-build
1415
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
@@ -138,3 +139,14 @@ install:
138139
touch $(OUTPUTDIR)/.nojekyll
139140
ghp-import -m "Generate Pelican site [ci skip]" -b $(GITHUB_PAGES_BRANCH) $(OUTPUTDIR)
140141
git push origin $(GITHUB_PAGES_BRANCH)
142+
143+
.PHONY: add-stable-doc
144+
add-stable-doc:
145+
# switch to GITHUB_PAGES_BRANCH where stable build is located
146+
git fetch origin $(GITHUB_PAGES_BRANCH)
147+
git checkout $(GITHUB_PAGES_BRANCH)
148+
git pull origin $(GITHUB_PAGES_BRANCH)
149+
# move the content of the stable build to the output dir
150+
mv ../$(STABLE_DOC_DIR) $(OUTPUTDIR)
151+
# switch back to main and get to doc directory
152+
git checkout main

doc/_static/style.css

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.announcement {
2+
background-color: #1f77b4;
3+
}
4+
5+
.sidebar-version {
6+
display: flex;
7+
flex-direction: row;
8+
align-items: center;
9+
justify-content: space-between;
10+
11+
padding-left: var(--sidebar-item-spacing-horizontal);
12+
padding-right: var(--sidebar-item-spacing-horizontal);
13+
margin-top: 0px;
14+
}
15+
16+
.sidebar-version-selected>* {
17+
display: flex;
18+
align-items: center;
19+
padding: 0.25em;
20+
border-radius: 0.25rem;
21+
background-color: #ff7f0e;
22+
color: white;
23+
pointer-events: none;
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div class="sidebar-tree sidebar-version">
2+
<span style="color: #767676;">Version</span>
3+
4+
<div style="display: flex; align-items: center; gap: 0.25em;">
5+
<span class="{{ 'sidebar-version-selected' if is_stable_doc else '' }}">
6+
<a style=" text-decoration: none;" href="stable/index.html">
7+
Stable
8+
</a>
9+
</span>
10+
11+
<span class="{{ '' if is_stable_doc else 'sidebar-version-selected' }}">
12+
<a style="text-decoration: none;" href="../index.html">
13+
Dev
14+
</a>
15+
</span>
16+
</div>
17+
</div>

doc/conf.py

+32-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
# custom ext, see ./sphinxext/gh_substitutions.py
6767
]
6868

69+
# set it to True to build a stable version of the documentation
70+
is_stable_doc = False
71+
6972
myst_enable_extensions = [
7073
"dollarmath",
7174
"amsmath"
@@ -76,6 +79,8 @@
7679
# Add any paths that contain templates here, relative to this directory.
7780
templates_path = ['_templates']
7881

82+
html_css_files = ["style.css"]
83+
7984
# The suffix(es) of source filenames.
8085
# You can specify multiple suffix as a list of string:
8186
# source_suffix = ['.rst', '.md']
@@ -208,7 +213,7 @@
208213

209214
# The name for this set of Sphinx documents. If None, it defaults to
210215
# "<project> v<release> documentation".
211-
#html_title = None
216+
html_title = f"skglm {version} documentation"
212217

213218
# A shorter title for the navigation bar. Default is the same as html_title.
214219
#html_short_title = None
@@ -241,7 +246,32 @@
241246
#html_use_smartypants = True
242247

243248
# Custom sidebar templates, maps document names to template names.
244-
#html_sidebars = {}
249+
html_sidebars = {
250+
"**": [
251+
"sidebar/brand.html",
252+
"sidebar/version_toggler.html", # version toggler template
253+
"sidebar/search.html",
254+
"sidebar/navigation.html",
255+
]
256+
}
257+
258+
# these variables will be available in the sphinx templates
259+
html_context = {
260+
"is_stable_doc": is_stable_doc
261+
}
262+
263+
264+
# when it's the dev version of the documentation, put a banner to warn the user
265+
# and a link to switch to the dev version of doc
266+
if not is_stable_doc:
267+
html_theme_options = {
268+
"announcement": (
269+
"You are viewing the documentation of the dev version of "
270+
"<code>skglm</code> which contains WIP features. "
271+
"View <a href='stable/index.html'>stable version</a>."
272+
)
273+
}
274+
245275

246276
# Additional templates that should be rendered to pages, maps page names to
247277
# template names.

0 commit comments

Comments
 (0)