Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with version-switcher and dirhtml builder #2002

Closed
cgohlke opened this issue Oct 1, 2024 · 0 comments · Fixed by #2004
Closed

Issues with version-switcher and dirhtml builder #2002

cgohlke opened this issue Oct 1, 2024 · 0 comments · Fixed by #2004
Assignees

Comments

@cgohlke
Copy link
Contributor

cgohlke commented Oct 1, 2024

Re #1795

Hello,

using Sphinx 8.0.2 with pydata-sphinx-theme 0.15.4 (or 0.16.0rc0), I am trying to get the version-switcher working with the dirhtml builder and ran into two issues:

  1. Page names like api/index (DOCUMENTATION_OPTIONS.pagename = 'api/index') are mapped to api/index/, not api/
  2. Some urls contain double slashes //, as already noted in fix version-switcher with dirhtml builder #1795 (comment)

The following patch works for me, but I haven't formally tested it:

diff --git a/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js b/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js
index 0c876e6..03a42a2 100644
--- a/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js
+++ b/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js
@@ -346,8 +346,8 @@ var setupSearchButtons = () => {
  */
 var getCurrentUrlPath = () => {
   if (DOCUMENTATION_OPTIONS.BUILDER == "dirhtml") {
-    return DOCUMENTATION_OPTIONS.pagename == "index"
-      ? `/`
+    return DOCUMENTATION_OPTIONS.pagename.endsWith("index")
+      ? `${DOCUMENTATION_OPTIONS.pagename.substring(0, DOCUMENTATION_OPTIONS.pagename.length - 5)}`
       : `${DOCUMENTATION_OPTIONS.pagename}/`;
   }
   return `${DOCUMENTATION_OPTIONS.pagename}.html`;

Does this look correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants