Skip to content

Pin RTD search query to current version - #328

Open
karlhillx wants to merge 3 commits into
sunpy:mainfrom
karlhillx:fix/327-rtd-search-version
Open

Pin RTD search query to current version#328
karlhillx wants to merge 3 commits into
sunpy:mainfrom
karlhillx:fix/327-rtd-search-version

Conversation

@karlhillx

@karlhillx karlhillx commented Jun 6, 2026

Copy link
Copy Markdown

Fixes #327.

Read the Docs v3 search defaults each project to its default version, usually stable. This caused searches from non-stable documentation builds to return links for /en/stable/.

This change reads the current project and version from the Read the Docs Addons data and pins only that project inside the search query using project:<slug>/<version>. Other projects remain on their own default versions.

External PR builds are not indexed, so they retain the existing unpinned search behavior. The Addons data is handled both when already available and when delivered later by the readthedocs-addons-data-ready event.

This also affects projects using the SunPy theme, including Astropy through the Astropy unified theme. See astropy/astropy#19866.

The v3 search API call in getReadTheDocsResults was missing the version
parameter, so RTD defaulted to the project's default version (stable).
On non-stable builds (latest, a release branch, a PR build) search
results linked to /en/stable/ pages instead of the version being read.

Capture versions.current.slug from the readthedocs-addons-data-ready
event and append &version=<slug> to the query.

Fixes sunpy#327.
@Cadair

Cadair commented Aug 26, 2026

Copy link
Copy Markdown
Member

Thanks for the PR. I can't see the modified request on the RTD preview. I don't know if this is because it's a PR or if something is bugged?

@karlhillx

karlhillx commented Aug 26, 2026

Copy link
Copy Markdown
Author

You were right... &version= was being ignored.

RTD expects the version in the search expression as project:<slug>/<version>. I’ve updated the PR to pin only the current project, skip unindexed external builds, and handle RTD metadata that loaded before the script.

The fix is pushed now.

Copilot AI lite review requested due to automatic review settings August 26, 2026 13:16

Copilot AI 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.

Pull request overview

This PR aims to keep Read the Docs “enhanced search” results pointing at the currently viewed documentation version (e.g., latest or a release branch) instead of defaulting links to stable.

Changes:

  • Adds a listener for the readthedocs-addons-data-ready event to capture the current RTD project/version slug.
  • Adjusts the RTD v3 search query construction to incorporate the captured version when building the project search filter.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/sunpy_sphinx_theme/theme/sunpy/static/js/rtd_enhanced_search.js Outdated
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.

rtd_enhanced_search.js hits v3 API without version, RTD returns stable results on non-stable builds

3 participants