Skip to content

feat: support multi-version docs#159

Merged
hnwyllmm merged 2 commits into
oceanbase:developfrom
taven-liu:feature/taven/support-multi-version
Jan 31, 2026
Merged

feat: support multi-version docs#159
hnwyllmm merged 2 commits into
oceanbase:developfrom
taven-liu:feature/taven/support-multi-version

Conversation

@taven-liu

@taven-liu taven-liu commented Jan 31, 2026

Copy link
Copy Markdown
Contributor

Summary

close #104

Solution Description

  1. 多版本文档构建系统
  • 集成 sphinx-multiversion 扩展,支持为多个分支和标签构建文档
  • 配置了版本白名单规则:
    • 标签格式:v ..*(如 v1.0.0, v1.1.0)
    • 分支:main 和 develop
  • 自动创建重定向页面,默认跳转到 develop 版本
  1. Makefile 新增命令
  • make docs-multiversion:构建所有版本的文档
  • make docs-serve:启动支持自动重载的开发服务器
  • make docs:单版本构建(已更新注释)

Summary by CodeRabbit

  • New Features

    • Multi-version documentation build and a local doc server with auto-reload for live previews
    • Version selector dropdown in the docs UI to switch between documentation versions
  • Documentation

    • New styling and banners for version-aware documentation and a redirect to the latest version for easy access

✏️ Tip: You can customize this high-level summary in your review settings.

@CLAassistant

CLAassistant commented Jan 31, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jan 31, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Build System
Makefile
Updated docs description to "Build documentation (single version)". Added docs-multiversion target to run docs/build_multiversion.sh and docs-serve target to run sphinx-autobuild for local serving.
Multi-version build script
docs/build_multiversion.sh
New script: strict error handling, optional venv activation, cleans docs/_build/html, runs sphinx-multiversion, and writes a redirect index to the latest version.
Sphinx configuration
docs/conf.py
Added sphinx_multiversion to extensions, configured smv_* whitelists/patterns, added html_css_files, templates_path, and html_context for GitHub metadata.
Templates & Styling
docs/_templates/layout.html, docs/_static/custom.css
Inserted a sidebar version selector dropdown into layout template; added extensive CSS for the selector, version-warning banner styling, and hiding the RTD version banner.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Dev as Developer
participant Make as Makefile
participant Script as build_multiversion.sh
participant SMV as sphinx-multiversion
participant Out as docs/_build/html
Dev->>Make: run make docs-multiversion
Make->>Script: execute docs/build_multiversion.sh
Script->>Script: activate venv (optional), clean previous build
Script->>SMV: invoke sphinx-multiversion to build versions
SMV->>Out: generate per-version HTML (*/index.html)
Script->>Out: write redirect index.html -> latest version (develop/index.html)
Dev->>Out: open served docs (or use make docs-serve to auto-reload)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
I hopped through docs with joyful cheer,
Built many versions far and near,
A dropdown lets each release appear,
Redirects lead the way so clear,
Sphinx and branches — hop, persevere!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: support multi-version docs' clearly and concisely summarizes the main change—adding multi-version documentation support to the project.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #104: multi-version documentation support via sphinx-multiversion, version whitelisting for tags and branches, automatic redirect generation, and new Makefile commands for building and serving documentation.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing multi-version documentation support as specified in issue #104; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread docs/_templates/version_warning.html Outdated
Comment on lines +1 to +6
{% 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>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 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:


🌐 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:


🏁 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 -10

Repository: 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 -20

Repository: oceanbase/pyseekdb

Length of output: 98


🏁 Script executed:

# Check docs/conf.py for sphinx-multiversion configuration
cat docs/conf.py | head -100

Repository: 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/null

Repository: 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.html

Repository: 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.

Comment thread docs/conf.py Outdated
@hnwyllmm

Copy link
Copy Markdown
Member

Please sign CLA.

@taven-liu taven-liu force-pushed the feature/taven/support-multi-version branch from c882826 to 0e5f298 Compare January 31, 2026 07:17
@taven-liu taven-liu closed this Jan 31, 2026
@taven-liu taven-liu reopened this Jan 31, 2026
@taven-liu

Copy link
Copy Markdown
Contributor Author

Please sign CLA.

Done

@hnwyllmm hnwyllmm merged commit 4eef55f into oceanbase:develop Jan 31, 2026
7 checks passed
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 this pull request may close these issues.

[Enhancement]: version support of document

3 participants