pydata / pydata-sphinx-theme

A clean, three-column Sphinx theme with Bootstrap for the PyData community
https://pydata-sphinx-theme.readthedocs.io
BSD 3-Clause "New" or "Revised" License
557 stars 300 forks source link

Enable user to overwrite `"Choose version"` as a default in the switcher field #1885

Open mosc9575 opened 2 weeks ago

mosc9575 commented 2 weeks ago

This is a feature request, to enable the user to overwrite "Choose version" with a string the user preferes.

In my case I want to show the build version of the docs if no version in the switcher.json matches.

This was the case before https://github.com/pydata/pydata-sphinx-theme/commit/5db8dff57b0bc5ced11ca7188d6ea636d695e2e8 was commited.

At the moment the relevant code line is this

https://github.com/pydata/pydata-sphinx-theme/blob/09849cc5112ab1e08d703a427459f2570f80a0aa/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/version-switcher.html#L16

and I suggest to change this line to

{{ theme_switcher.get("version_match_default")|default:"Choose version" }}  <!-- this text may get changed later by javascript -->

so the user can define his personal default value in the conf.py by adding version_match_default to the switcher settings.

For example this should be possible.

  "switcher": {
      "json_url": json_url,
      "version_match_default":  "3.2.1rc",
      "version_match": version_match,
  }
drammock commented 1 week ago

If the switcher says "choose version" it indicates that something went wrong in determining what version of the docs are currently being viewed (and matching that up with a corresponding entry in the switcher JSON array). In other words, it's a "graceful failure mode" so that the intent of the dropdown is still clear. I'd rather not make it possible to have the switcher appear as if it detected the version but have it actually display something (possibly) inaccurate.

Can you check the Javascript console of your browser when your site is loaded, to see if:

mosc9575 commented 1 week ago

I know, that "Choose version" shows up, if no version match can be found in the switcher.json . The original post comes from bokeh #13477. In an earlier version, the default wasn't "Choose version" but the "dev"-version.

At the moment we have to update the switcher.json for each development version, if we want the old behavior. This is somehow annoying. And after an release the latest dev versions can still be found on the web because they arn't removed, but the switcher.json will not have an entry for each older dev version. This means, it will display "Choose version" again.

In this issue I want to set the default by hand, if this is possible.