Comments (6)
Yes, looks like the documentation for the version selector needs to be updated as well.
One the drawbacks to how both readthedocs versions work, and also how I believe sphinxcontrib-versioning works, is that the list of versions is hard coded into the generated HTML files of each version. Consequently, every time you add a new version, you have to rebuild the docs for every previous version, which poses a number of problems:
- If you have e.g. 100 versions, in order to add 1 more version you have to rebuild the docs 100 times.
- Old versions of your docs may no longer build with new versions of Python, new versions of other system dependencies, etc. (when using autodoc/autosummary with C extensions, you also have to actually build your package to build the docs).
In contrast, docs.python.org, the mkdocs "mike" plugin, and this theme use a different approach, where the version menu is generated dynamically via JavaScript. That allows you to modify the list of versions without rebuilding the documentation.
As far as the specifics regarding version selector for this theme:
There is no HTML template for versions, because versions are injected from the javascript code instead:
You can add a version selector by adding the following to html_theme_options
:
"version_dropdown": True,
"version_info": [
{"version": "2.0", "title": "2.0", "aliases": ["latest"]},
{"version": "1.0", "title": "1.0", "aliases": []},
],
If it isn't a relative path, you can make "version" a full URL.
In this example I have specified the list of versions inline in the config, which is similar to how readthedocs or sphinxcontrib-versioning would do it -- but that is just for demonstration purposes.
Instead of "version_info", you can instead specify "version_json": "versions.json" or similar. That option only works if your docs are served from a webserver (does not work if you use file://
url) and in that case the "version_json" file is resolved relative to the parent directory of the directory that your documentation is served from. So for example, you should have:
/versions.json
/1.0/index.html
/2.0/index.html
from sphinx-immaterial.
As I was writing the message above I tried it out and it did work. The "aliases" member is required, though it may be an empty list --- if it is missing you get an error in the JavaScript console. That may have been a limitation I introduced with my own modifications to the javascript, not sure.
from sphinx-immaterial.
The last tidbit seems a worthy addition to the docs.
It's almost been a week since I tried the version selector feature, but I think I tried all avenues (version_json
and version_info
with the expected mike syntax) with no joy. I didn't specify an alias
field though, may be that will change something.
Have you been able to ever use the version selector dropdown successfully? I assume the version_dropdown_text
is a relic from sphinx-material theme's docs.
from sphinx-immaterial.
the "version_json" file is resolved relative to the parent directory of the directory that your documentation is served from
This is a little confusing. I think what you're saying is that the versions.json file needs to be somehow copied into the _build directory (or the parent dir of whatever the user specifies as the builder's output). If so, then how should I document this? Would it require the user to also specify html_extra_path
option in conf.py?
from sphinx-immaterial.
If the user has in their documentation source directory:
index.rst
something.rst
conf.py
...
Then the build output will have:
index.html
something.html
...
The user should then deploy this to their webserver as:
1.0/
index.html
something.html
...
2.0/
index.html
something.html
...
versions.json
The versions.json
file is in the parent directory that contains all of the versions. The user needs to set up some mechanism for updating it when they deploy a new version. It doesn't make sense to ask sphinx to copy versions.json
since Sphinx is just responsible for building the documentation for a single version, and versions.json
goes outside the build tree of any single version, and the user needs to create a mechanism for generating it.
from sphinx-immaterial.
Good notes. I'm adding them to the revisions I'm working on. I'll be using the version selector to demonstrate switching from gh-pages to RTD (& vice-versa) in conf.py.
from sphinx-immaterial.
Related Issues (20)
- 0.11.7: pytest is failing on missing `sphinx_immaterial_pybind11_issue_134` module HOT 7
- Error while following sphinx tutorial about creating a todo ext HOT 8
- `@overload` expands common type unions HOT 5
- pydantic 2.5.0 release just broke this package HOT 6
- "Edit this page" on RTD HOT 9
- use libgit2 directly in merge script HOT 2
- Extra whitespace for rendered footnotes/citations HOT 10
- Rendering of :kbd: role is a bit off HOT 7
- document the `theme_result` extension
- Feature request: Mermaid js 10.x
- genindex / modindex seems broken HOT 1
- [jupiter-book] Missing Table of Contents HOT 1
- Google Fonts API key invalid? HOT 16
- "Copy to clipboard" and "Back to top" Buttons Disappear After Adjusting Theme Settings HOT 7
- Broken link to fontawesome/brands icons HOT 1
- implement blog plugin from upstream
- add role for custom hyperlinks HOT 1
- add extension for supplementing git stats about doc sources HOT 1
- add directive(s) to support grids
- sphinx~=7.3.0 breaks sphinx-immaterial HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sphinx-immaterial.