feat: support multi-version docs#159
Conversation
📝 WalkthroughWalkthroughAdds multi-version documentation support: new Sphinx multiversion configuration, a build script, Makefile targets to build/serve multi-version docs, and UI/templates/CSS to display a version selector and related banners. Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@docs/_templates/version_warning.html`:
- Around line 1-6: The template uses pathto('index', 1) |
replace(current_version, 'develop') which won't produce a correct cross-version
link; replace that expression with the sphinx-multiversion helper
vpathto('develop') and update the anchor to use {{ vpathto('develop') }} (keep
the existing condition using current_version and ensure the {% endif %} is
present) so the link correctly points to the develop version across multiversion
builds.
In `@docs/conf.py`:
- Around line 77-83: The html_context 'github_version' is static and causes
"Edit on GitHub" links to always point to 'develop'; add a setup(app) hook that
connects to the 'html-page-context' event and in the handler set
context['github_version'] = context.get('current_version',
app.config.html_context.get('github_version', 'develop')) so each rendered
version uses the provided current_version when available; implement the handler
function and register it via app.connect('html-page-context', your_handler) in
conf.py, referencing html_context and the event name to locate where to change.
🧹 Nitpick comments (1)
docs/build_multiversion.sh (1)
4-4: Consider stricter bash error handling (set -euo pipefail).
This avoids silent failures from unset variables or pipeline errors.🔧 Suggested tweak
-set -e +set -euo pipefail
| {% if current_version != 'develop' and current_version != 'main' %} | ||
| <div class="version-warning"> | ||
| <strong>⚠️ 注意:</strong> | ||
| 您正在查看 <strong>{{ current_version }}</strong> 版本的文档。 | ||
| <a href="{{ pathto('index', 1) | replace(current_version, 'develop') }}">点击这里查看最新开发版本</a> | ||
| </div> |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Sphinx pathto() function documentation relative path version
💡 Result:
In Sphinx HTML theme templates (Jinja), pathto() has two common “modes”:
pathto(document): returns a URL (typically a relative link from the current page) to another built Sphinx document. [1] (sphinx-doc.org)pathto(file, 1)(i.e.,pathto(file, True)): returns the path to a file that is relative to the root of the generated output (commonly used for static assets like_static/...). [1] (sphinx-doc.org)
This behavior is consistent across older Sphinx docs as well (e.g., 1.7.9 shows the same definitions). [2] (sphinx-hxl.readthedocs.io)
[1] https://www.sphinx-doc.org/en/master/development/html_themes/templating.html
[2] https://sphinx-hxl.readthedocs.io/en/stable/templating.html
Citations:
- 1: https://www.sphinx-doc.org/en/master/development/html_themes/templating.html
- 2: https://www.sphinx-doc.org/en/master/development/html_themes/templating.html
- 3: https://sphinx-hxl.readthedocs.io/en/stable/templating.html?utm_source=openai
🌐 Web query:
sphinx-multiversion how to link between versions recommended approach
💡 Result:
Recommended approach in sphinx-multiversion is to generate cross-version links at the template (Jinja) level, using the HTML-context helpers it provides—rather than hard-coding /vX.Y/… URLs.
1) Link to “the same page in another version” (best default)
Use vhasdoc() to check availability and vpathto() to compute the correct URL to the current page in another version (falling back to that version’s master_doc if the page doesn’t exist). (sphinx-contrib.github.io)
{# e.g. in a theme template like layout.html or a custom version switcher #}
{% if vhasdoc('v2.0.0') %}
<a href="{{ vpathto('v2.0.0') }}">View this page in v2.0.0</a>
{% else %}
<a href="{{ vpathto('v2.0.0') }}">Go to v2.0.0 docs</a>
{% endif %}2) Build a version switcher (recommended UX)
Iterate versions and link with each version’s per-page item.url (this already points to “this page in that version”). (sphinx-contrib.github.io)
<ul>
{% for item in versions %}
<li><a href="{{ item.url }}">{{ item.name }}</a></li>
{% endfor %}
</ul>3) Link to “latest released” from anywhere
Use latest_version + vpathto(latest_version.name) to avoid hard-coding what “latest” is. (sphinx-contrib.github.io)
<a href="{{ vpathto(latest_version.name) }}">Latest docs ({{ latest_version.name }})</a>When to use Intersphinx instead
If your “other versions” are actually built/published as separate doc sites (not via sphinx-multiversion’s single combined build), then treat each version as an external docs set and use sphinx.ext.intersphinx with separate inventories. (sphinx-doc.org)
Citations:
- 1: https://sphinx-contrib.github.io/multiversion/main/context.html
- 2: https://sphinx-contrib.github.io/multiversion/main/context.html
- 3: https://sphinx-contrib.github.io/multiversion/main/context.html
- 4: https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html?utm_source=openai
🏁 Script executed:
# Check if there's sphinx configuration and multiversion setup
find . -name "conf.py" -o -name "*.py" | head -20
git ls-files | grep -E "(conf\.py|setup\.py|requirements)" | head -10Repository: oceanbase/pyseekdb
Length of output: 748
🏁 Script executed:
# Search for other version templates or multiversion config
find docs -type f -name "*.html" -o -name "*.cfg" | grep -E "(version|multiversion)" | head -20Repository: oceanbase/pyseekdb
Length of output: 98
🏁 Script executed:
# Check docs/conf.py for sphinx-multiversion configuration
cat docs/conf.py | head -100Repository: oceanbase/pyseekdb
Length of output: 1913
🏁 Script executed:
# Look for any multiversion configuration or extensions
grep -r "multiversion\|vpathto\|vhasdoc" docs/ --include="*.py" --include="*.html" 2>/dev/null || echo "No multiversion patterns found"Repository: oceanbase/pyseekdb
Length of output: 150
🏁 Script executed:
# Check if there are other templates using pathto or version awareness
find docs/_templates -type f -name "*.html" -exec basename {} \; 2>/dev/nullRepository: oceanbase/pyseekdb
Length of output: 94
🏁 Script executed:
# Look at the version_warning.html more carefully and surrounding context
cat -n docs/_templates/version_warning.htmlRepository: oceanbase/pyseekdb
Length of output: 400
Use sphinx-multiversion's vpathto() helper to properly link between versions.
The current approach using {{ pathto('index', 1) | replace(current_version, 'develop') }} won't work. Since pathto('index', 1) returns a path relative to the output root (e.g., index.html) without the version prefix, replacing current_version in it finds no match and produces no change.
Since this template is part of a sphinx-multiversion build, use the multiversion context helpers instead:
{% if current_version != 'develop' and current_version != 'main' %}
<div class="version-warning">
<strong>⚠️ 注意:</strong>
您正在查看 <strong>{{ current_version }}</strong> 版本的文档。
<a href="{{ vpathto('develop') }}">点击这里查看最新开发版本</a>
</div>
{% endif %}vpathto() is designed to handle cross-version linking correctly within sphinx-multiversion builds.
🤖 Prompt for AI Agents
In `@docs/_templates/version_warning.html` around lines 1 - 6, The template uses
pathto('index', 1) | replace(current_version, 'develop') which won't produce a
correct cross-version link; replace that expression with the sphinx-multiversion
helper vpathto('develop') and update the anchor to use {{ vpathto('develop') }}
(keep the existing condition using current_version and ensure the {% endif %} is
present) so the link correctly points to the develop version across multiversion
builds.
|
Please sign CLA. |
c882826 to
0e5f298
Compare
Done |
Summary
close #104
Solution Description
make docs-multiversion:构建所有版本的文档make docs-serve:启动支持自动重载的开发服务器make docs:单版本构建(已更新注释)Summary by CodeRabbit
New Features
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.