From c67a88532a0e062bfde8d727de44f55f4dd4baff Mon Sep 17 00:00:00 2001 From: Badr MOUFAD <65614794+Badr-MOUFAD@users.noreply.github.com> Date: Tue, 14 Nov 2023 10:37:57 +0100 Subject: [PATCH] DOC - Enable viewing dev and stable versions of package documentation (#206) --- .circleci/config.yml | 12 ++++++++ doc/Makefile | 12 ++++++++ doc/_static/style.css | 24 +++++++++++++++ doc/_templates/sidebar/version_toggler.html | 17 +++++++++++ doc/conf.py | 34 +++++++++++++++++++-- 5 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 doc/_static/style.css create mode 100644 doc/_templates/sidebar/version_toggler.html diff --git a/.circleci/config.yml b/.circleci/config.yml index bcef5d4d6..c18cd28e7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -78,9 +78,21 @@ jobs: chmod og= ~/.ssh/config cd doc; pip install ghp-import; + make add-stable-doc make install fi + # Add stable documentation + - run: + name: stable_doc + command: | + set -e + mkdir -p ~/.ssh + echo -e "Host *\nStrictHostKeyChecking no" > ~/.ssh/config + chmod og= ~/.ssh/config + cd doc; + make add-stable-doc + # Save the outputs - store_artifacts: path: doc/_build/html/ diff --git a/doc/Makefile b/doc/Makefile index c592b30a2..e2d6c7c79 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -9,6 +9,7 @@ BUILDDIR = _build GITHUB_PAGES_BRANCH = gh-pages OUTPUTDIR = _build/html +STABLE_DOC_DIR = stable # User-friendly check for sphinx-build ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) @@ -138,3 +139,14 @@ install: touch $(OUTPUTDIR)/.nojekyll ghp-import -m "Generate Pelican site [ci skip]" -b $(GITHUB_PAGES_BRANCH) $(OUTPUTDIR) git push origin $(GITHUB_PAGES_BRANCH) + +.PHONY: add-stable-doc +add-stable-doc: +# switch to GITHUB_PAGES_BRANCH where stable build is located + git fetch origin $(GITHUB_PAGES_BRANCH) + git checkout $(GITHUB_PAGES_BRANCH) + git pull origin $(GITHUB_PAGES_BRANCH) +# move the content of the stable build to the output dir + mv ../$(STABLE_DOC_DIR) $(OUTPUTDIR) +# switch back to main and get to doc directory + git checkout main diff --git a/doc/_static/style.css b/doc/_static/style.css new file mode 100644 index 000000000..3deebf01f --- /dev/null +++ b/doc/_static/style.css @@ -0,0 +1,24 @@ +.announcement { + background-color: #1f77b4; +} + +.sidebar-version { + display: flex; + flex-direction: row; + align-items: center; + justify-content: space-between; + + padding-left: var(--sidebar-item-spacing-horizontal); + padding-right: var(--sidebar-item-spacing-horizontal); + margin-top: 0px; +} + +.sidebar-version-selected>* { + display: flex; + align-items: center; + padding: 0.25em; + border-radius: 0.25rem; + background-color: #ff7f0e; + color: white; + pointer-events: none; +} diff --git a/doc/_templates/sidebar/version_toggler.html b/doc/_templates/sidebar/version_toggler.html new file mode 100644 index 000000000..afd2a3e1f --- /dev/null +++ b/doc/_templates/sidebar/version_toggler.html @@ -0,0 +1,17 @@ + diff --git a/doc/conf.py b/doc/conf.py index 58bf930e0..afa64bdef 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -66,6 +66,9 @@ # custom ext, see ./sphinxext/gh_substitutions.py ] +# set it to True to build a stable version of the documentation +is_stable_doc = False + myst_enable_extensions = [ "dollarmath", "amsmath" @@ -76,6 +79,8 @@ # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] +html_css_files = ["style.css"] + # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # source_suffix = ['.rst', '.md'] @@ -208,7 +213,7 @@ # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +html_title = f"skglm {version} documentation" # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None @@ -241,7 +246,32 @@ #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {} +html_sidebars = { + "**": [ + "sidebar/brand.html", + "sidebar/version_toggler.html", # version toggler template + "sidebar/search.html", + "sidebar/navigation.html", + ] +} + +# these variables will be available in the sphinx templates +html_context = { + "is_stable_doc": is_stable_doc +} + + +# when it's the dev version of the documentation, put a banner to warn the user +# and a link to switch to the dev version of doc +if not is_stable_doc: + html_theme_options = { + "announcement": ( + "You are viewing the documentation of the dev version of " + "skglm which contains WIP features. " + "View stable version." + ) + } + # Additional templates that should be rendered to pages, maps page names to # template names.