Repository: nilearn/nilearn

Issue:
Add back stable/dev banners to website
The green `stable` and red `dev` banners were not transferred over to the new documentation theme. 

To do:
- add banners back
- (optional) add a toggle to easily go back and forth between versions



Discussion:
Furo makes it easy to add an [announcement banner](https://pradyunsg.me/furo/customisation/announcement/): it would be a one-line change in our `conf.py`.

I guess we could try to have 2 configuration files (one for prod, one for dev builds) but it's a shame to duplicate files just for the sake of adding one line... Any idea on how to achieve this elegantly? :slightly_smiling_face: 
Could we infer [the version number](https://protips.readthedocs.io/git-tag-version.html) of `nilearn` and pass "Unstable" if it's at an untagged commit and "Stable" if it doesn't include a commit string ?

_Or_ we could just [pass an environmental variable](https://stackoverflow.com/questions/61216495/change-variable-in-sphinx-conf-py-as-part-of-build-command) during our "Stable" builds to control this ?
Oh nice, I like both ideas! I guess the first one is the most straightforward, as setting up different env variables depending on dev / prod builds might take more time (although we might like to have that in the long run).
Yes, I think the first option in good. `release` as a variable is already defined in `conf.py` and a similar thing is done with binder: https://github.com/nilearn/nilearn/blob/9eddcf0953e29e7782f1f29b32a0ec48e0a41573/doc/conf.py#L345-L348

Resolving patch:
diff --git a/doc/conf.py b/doc/conf.py
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -14,6 +14,7 @@
 
 import sys
 import os
+import re
 import shutil
 import sphinx
 from nilearn.version import _compare_version
@@ -101,12 +102,16 @@
 # The version info for the project you're documenting, acts as replacement for
 # |version| and |release|, also used in various other places throughout the
 # built documents.
-#
-# The short X.Y version.
-version = ''
-# The full version, including alpha/beta/rc tags.
+
+# Latest release version
+latest_release = re.match(
+    r'v?([0-9]+.[0-9]+.[0-9]+).*',
+    os.popen('git describe --tags').read().strip()
+).groups()[0]
+
+# The full current version, including alpha/beta/rc tags.
 import nilearn
-release = nilearn.__version__
+current_version = nilearn.__version__
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
@@ -179,12 +184,29 @@
 # further.  For a list of options available for each theme, see the
 # documentation.
 html_theme_options = {
+    "dark_css_variables": {
+        "color-announcement-background": "#935610",
+        "color-announcement-text": "#FFFFFF",
+    },
     "light_css_variables": {
         "admonition-font-size": "100%",
-        "admonition-title-font-size": "100%"
-    }
+        "admonition-title-font-size": "100%",
+        "color-announcement-background": "#FBB360",
+        "color-announcement-text": "#111418",
+    },
 }
 
+# Add banner in case version is not stable
+if "dev" in current_version:
+    html_theme_options["announcement"] = (
+        '<p>This is the development documentation '
+        f'of nilearn ({current_version}) '
+        '<a class="sd-sphinx-override sd-badge sd-text-wrap '
+        'sd-btn-outline-dark reference external" '
+        'href="https://nilearn.github.io">'
+        f'<span>Switch to stable version ({latest_release})</span></a></p>'
+    )
+
 # Add any paths that contain custom themes here, relative to this directory.
 # html_theme_path = ['themes']
 
@@ -342,10 +364,10 @@
     'nipy': ('https://nipy.org/%s', None),
 }
 
-if 'dev' in release:
+if 'dev' in current_version:
     binder_branch = 'main'
 else:
-    binder_branch = release
+    binder_branch = current_version
 
 sphinx_gallery_conf = {
     'doc_module': 'nilearn',


Test patch: