DOC Places newest highlights first in subsection
@@ -30,6 +30,7 @@ sys.path.insert(0, os.path.abspath("sphinxext"))
from github_link import make_linkcode_resolve
import sphinx_gallery
import matplotlib as mpl
+from sphinx_gallery.sorting import ExampleTitleSortKey
# -- General configuration ---------------------------------------------------
@@ -359,6 +360,24 @@ class SubSectionTitleOrder:
return directory
+class SKExampleTitleSortKey(ExampleTitleSortKey):
+ """Sorts release highlights based on version number."""
+
+ def __call__(self, filename):
+ title = super().__call__(filename)
+ prefix = "plot_release_highlights_"
+
+ # Use title to sort if not a release highlight
+ if not filename.startswith(prefix):
+ return title
+
+ major_minor = filename[len(prefix) :].split("_")[:2]
+ version_float = float(".".join(major_minor))
+
+ # negate to place the newest version highlights first
+ return -version_float
+
+
sphinx_gallery_conf = {
"doc_module": "sklearn",
"backreferences_dir": os.path.join("modules", "generated"),
@@ -367,6 +386,7 @@ sphinx_gallery_conf = {
"examples_dirs": ["../examples"],
"gallery_dirs": ["auto_examples"],
"subsection_order": SubSectionTitleOrder("../examples"),
+ "within_subsection_order": SKExampleTitleSortKey,
"binder": {
"org": "scikit-learn",
"repo": "scikit-learn",
