From 86f6d6456fa3ee266443663c53be8bf1041579e0 Mon Sep 17 00:00:00 2001 From: Pamphile Roy Date: Thu, 20 Jan 2022 13:25:12 +0100 Subject: [PATCH 1/5] ENH: add optional extra_classes in version-switcher --- docs/user_guide/configuring.rst | 2 ++ .../pydata_sphinx_theme/_templates/version-switcher.html | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/docs/user_guide/configuring.rst b/docs/user_guide/configuring.rst index f1196869e..faab8afd7 100644 --- a/docs/user_guide/configuring.rst +++ b/docs/user_guide/configuring.rst @@ -386,6 +386,8 @@ each have one or two fields: switcher. - ``name``: an optional name to display in the switcher dropdown instead of the version string (e.g., "latest", "stable", "dev", etc). +- ``extra_classes``: an optional list of classes to add to a version + (e.g., ``["dev", "hide"]``). Here is an example JSON file: diff --git a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html index 10d6b75d5..90d34968c 100644 --- a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html +++ b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html @@ -65,6 +65,13 @@ // for that version of the docs. node.onclick = checkPageExistsAndRedirect; $("#version_switcher_menu").append(node); + // Add extra class to entries. Can be combined with "active" + // if it's only for styling the active version + if ("extra_classes" in entry) { + $.each(entry.extra_classes, function(index, extra_class) { + node.classList.add(extra_class); + }); + } // replace dropdown button text with the preferred display name of // this version, rather than using sphinx's {{ version }} variable. // also highlight the dropdown entry for the currently-viewed From e98bd62632aca9589bf26a779ad4e5502eedd0b6 Mon Sep 17 00:00:00 2001 From: Pamphile Roy Date: Mon, 24 Jan 2022 22:17:43 +0100 Subject: [PATCH 2/5] MAINT: move extra_classes to active version only --- docs/user_guide/configuring.rst | 3 ++- .../_templates/version-switcher.html | 13 ++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/user_guide/configuring.rst b/docs/user_guide/configuring.rst index faab8afd7..c536bffe4 100644 --- a/docs/user_guide/configuring.rst +++ b/docs/user_guide/configuring.rst @@ -387,7 +387,8 @@ each have one or two fields: - ``name``: an optional name to display in the switcher dropdown instead of the version string (e.g., "latest", "stable", "dev", etc). - ``extra_classes``: an optional list of classes to add to a version - (e.g., ``["dev", "hide"]``). + (e.g., ``["dev", "hide"]``). These classes are only added when the version + is active. Here is an example JSON file: diff --git a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html index 90d34968c..d31b1bd3d 100644 --- a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html +++ b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html @@ -65,13 +65,6 @@ // for that version of the docs. node.onclick = checkPageExistsAndRedirect; $("#version_switcher_menu").append(node); - // Add extra class to entries. Can be combined with "active" - // if it's only for styling the active version - if ("extra_classes" in entry) { - $.each(entry.extra_classes, function(index, extra_class) { - node.classList.add(extra_class); - }); - } // replace dropdown button text with the preferred display name of // this version, rather than using sphinx's {{ version }} variable. // also highlight the dropdown entry for the currently-viewed @@ -79,6 +72,12 @@ if (entry.version == "{{ theme_switcher.get('version_match') }}") { node.classList.add("active"); $("#version_switcher_button").text(entry.name); + // Add extra class to the entry + if ("extra_classes" in entry) { + $.each(entry.extra_classes, function(index, extra_class) { + node.classList.add(extra_class); + }); + } } }); }); From d7616a9760f8d763ed08347121c1d66ebc41b26d Mon Sep 17 00:00:00 2001 From: Pamphile Roy Date: Tue, 25 Jan 2022 12:02:37 +0100 Subject: [PATCH 3/5] MAINT: move extra_classes to button --- .../pydata_sphinx_theme/_templates/version-switcher.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html index d31b1bd3d..aa7f3372b 100644 --- a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html +++ b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html @@ -72,10 +72,10 @@ if (entry.version == "{{ theme_switcher.get('version_match') }}") { node.classList.add("active"); $("#version_switcher_button").text(entry.name); - // Add extra class to the entry + // Add extra class to the button for the selected entry if ("extra_classes" in entry) { $.each(entry.extra_classes, function(index, extra_class) { - node.classList.add(extra_class); + $("#version_switcher_menu").classList.add(extra_class); }); } } From c50de2db4d64e9457c8d87ee40285c0d0e777446 Mon Sep 17 00:00:00 2001 From: Pamphile Roy Date: Tue, 25 Jan 2022 12:21:36 +0100 Subject: [PATCH 4/5] DOC: add extra_classes in one example --- docs/user_guide/configuring.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/user_guide/configuring.rst b/docs/user_guide/configuring.rst index c536bffe4..bab8c2c98 100644 --- a/docs/user_guide/configuring.rst +++ b/docs/user_guide/configuring.rst @@ -386,9 +386,9 @@ each have one or two fields: switcher. - ``name``: an optional name to display in the switcher dropdown instead of the version string (e.g., "latest", "stable", "dev", etc). -- ``extra_classes``: an optional list of classes to add to a version - (e.g., ``["dev", "hide"]``). These classes are only added when the version - is active. +- ``extra_classes``: an optional list of classes to add to the switcher + button for a given version (e.g., ``["dev", "rc"]``). These classes are only + added when the version is active. Here is an example JSON file: @@ -399,6 +399,10 @@ Here is an example JSON file: "name": "v2.1 (stable)", "version": "2.1" }, + { + "version": "2.1rc1", + "extra_classes": ["dev", "rc"] + }, { "version": "2.0" }, From 822536fd1038e799f5e9ecefe706e9cf06227396 Mon Sep 17 00:00:00 2001 From: Pamphile Roy Date: Tue, 8 Feb 2022 22:11:37 +0100 Subject: [PATCH 5/5] Update src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html Co-authored-by: Chris Holdgraf --- .../pydata_sphinx_theme/_templates/version-switcher.html | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html index aa7f3372b..acffb9bd5 100644 --- a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html +++ b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/_templates/version-switcher.html @@ -74,9 +74,7 @@ $("#version_switcher_button").text(entry.name); // Add extra class to the button for the selected entry if ("extra_classes" in entry) { - $.each(entry.extra_classes, function(index, extra_class) { - $("#version_switcher_menu").classList.add(extra_class); - }); + $("#version_switcher_menu").classList.add(...entry.extra_classes); } } });