Skip to content

Commit

Permalink
ENH: add optional per version url in version-switcher (#575)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Holdgraf <choldgraf@gmail.com>
  • Loading branch information
tupui and choldgraf committed Feb 8, 2022
1 parent 8453f38 commit 052a7fa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions docs/user_guide/configuring.rst
Expand Up @@ -378,14 +378,16 @@ Add a JSON file to define your switcher's versions

First, write a JSON file stating which versions of your docs will be listed in
the switcher's dropdown menu. That file should contain a list of entries that
each have one or two fields:
each can have the following fields:

- ``version``: a version string. This will be inserted into
``switcher['url_template']`` to create the links to other docs versions, and
also checked against ``switcher['version_match']`` to provide styling to the
switcher.
- ``name``: an optional name to display in the switcher dropdown instead of the
version string (e.g., "latest", "stable", "dev", etc).
- ``url``: an optional URL. If provided, it links the version to ``url``
instead of ``switcher['url_template']``.

Here is an example JSON file:

Expand All @@ -400,8 +402,9 @@ Here is an example JSON file:
"version": "2.0"
},
{
"version": "1.0"
},
"version": "1.0",
"url": "https://mysite.org/en/1.0/index.html"
}
]
See the discussion of ``switcher['json_url']`` (below) for options of where to
Expand Down
Expand Up @@ -58,7 +58,9 @@
node.textContent = `${entry.name}`;
// get the base URL for that doc version, add the current page's
// path to it, and set as `href`
entry.url = buildURL(entry);
if (!("url" in entry)) {
entry.url = buildURL(entry);
}
node.setAttribute("href", `${entry.url}${currentFilePath}`);
// on click, AJAX calls will check if the linked page exists before
// trying to redirect, and if not, will redirect to the homepage
Expand Down

0 comments on commit 052a7fa

Please sign in to comment.