Open kevinh-hcl opened 1 month ago
Thanks for reporting and the very detailed explanations. Yes, it sounds like a currently unhandled combination of configuration settings when using mike. I'm not sure it's a bug, since we don't advertise the canonical_version
setting anywhere in our documentation, so I'll tag this as an chance request. Since you have already invested some time into tracking down the cause, would you like to work on this in a PR? Happy to collaborate. Shouldn't be too hard to support ☺️
Thank you. I drafted a first idea of how this could be handled in https://github.com/squidfunk/mkdocs-material/pull/7227. Any feedback is appreciated
Thanks for the PR! Please give me some time to check it out and give it a spin.
Context
We are using
mkdocs-material
together withmike
for our documentation.To improve SEO we set the
canonical_version
inmike
. This sets therel="canonical"
link
on every page and also leads to thesitemap.xml
in each version using the canonical links (withlatest
). 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 thecanonical_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
latest
in allsitemap.xml
Related
mike
documentation and codesite_url
fromcanonical_version
Reproduction in a fork from
mkdocs-material-example-versioning
canonical_version
0.5
(withcanonical_version
). You can switch FROM this versions to others just fine0.4
. Switch TO0.5
and get redirected to the homepage0.5
sitemap0.4
sitemapReproduction
9.5.25-version-switcher-canonical.zip
Steps to reproduce
9.5.25-version-switcher-canonical.zip
and navigate to the extracted folderpip install --upgrade --force-reinstall mike==2.1.1 mkdocs-material==9.5.25 mkdocs==1.6.0
mkdocs.yml
remove the- info
from theplugins
section and save the changesmike deploy canonical
mkdocs.yml
remove thecanonical_version: latest
frommike
in theplugins
section and save the changesmike deploy no-canonical latest
mike serve
Working as expected:
Not working as expected:
Browser
Chrome
Before submitting