-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Version switcher fails to stay on the same page when canonical_version is set in mike #7226
Description
Context
We are using mkdocs-material together with mike for our documentation.
To improve SEO we set the canonical_version in mike. This sets the rel="canonical" link on every page and also leads to the sitemap.xml in each version using the canonical links (with latest). This seems to be the expected way of handling canonical URLs according to Google Search Central and others.
Bug description
When switching from a sub page of any version to a version that was built with the canonical_version you get redirected to the homepage of the version. The expected behaviour would be to stay on the same sub page, but in a different version.
From what I can see this is probably due to mkdocs-material using the sitemap of the version to determine if a sub page is available in that version. Since the sitemap always uses the canonical_version instead of the actual version, the page is not found and it falls back to the homepage.
Related links
Related documentation
Pointer from a previous discussion
Related mike documentation and code
Reproduction in a fork from mkdocs-material-example-versioning
- Setting
canonical_version - Github Pages Version
0.5(withcanonical_version). You can switch FROM this versions to others just fine - Github Pages Version
0.4. Switch TO0.5and get redirected to the homepage 0.5sitemap0.4sitemap
Reproduction
9.5.25-version-switcher-canonical.zip
Steps to reproduce
- unzip
9.5.25-version-switcher-canonical.zipand navigate to the extracted folder - (Optional: I had to remove the venv due to the size limitation in the .zip upload. Please follow https://squidfunk.github.io/mkdocs-material/guides/creating-a-reproduction/#environment to create a venv and activate it)
- Install the dependencies using
pip install --upgrade --force-reinstall mike==2.1.1 mkdocs-material==9.5.25 mkdocs==1.6.0 - In
mkdocs.ymlremove the- infofrom thepluginssection and save the changes - Deploy a first version using
mike deploy canonical - In
mkdocs.ymlremove thecanonical_version: latestfrommikein thepluginssection and save the changes - Deploy a second version using
mike deploy no-canonical latest - Serve the documentation locally using
mike serve
Working as expected:
- Open http://localhost:8000/canonical/subpage/
- Switch to the no-canonical version
- The version shows the correct page
- (Optional: check http://localhost:8000/no-canonical/sitemap.xml of the target version)
Not working as expected:
- Open http://localhost:8000/no-canonical/subpage/
- Switch to the canonical version
- Redirected to the homepage
- (Optional: check http://localhost:8000/canonical/sitemap.xml of the target version)
Browser
Chrome
Before submitting
- I have read and followed the bug reporting guidelines.
- I have attached links to the documentation, and possibly related issues and discussions.
- I assure that I have removed all customizations before submitting this bug report.
- I have attached a .zip file with a minimal reproduction using the built-in info plugin.