-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Duplicated version menu on navigation for mkdocs #12032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi. Did you fix this issue already? I can't reproduce it. |
Nope, still happening for me. I've tried on four separate browsers (Vivaldi, Firefox, Chrome, Edge), on three devices (Linux desktop, Android, Windows 11) |
Are you using the example from our docs to generate that version selector? This one https://docs.readthedocs.com/platform/latest/intro/mkdocs.html#integrate-the-read-the-docs-version-menu-into-your-site-navigation |
Yup, here's the entirety of our document.addEventListener("DOMContentLoaded", function(event) {
// Trigger Read the Docs' search addon instead of Material MkDocs default
document.querySelector(".md-search__input").addEventListener("focus", (e) => {
const event = new CustomEvent("readthedocs-search-show");
document.dispatchEvent(event);
});
});
// Use CustomEvent to generate the version selector
document.addEventListener(
"readthedocs-addons-data-ready",
function (event) {
const config = event.detail.data();
const versioning = `
<div class="md-version">
<button class="md-version__current" aria-label="Select version">
${config.versions.current.slug}
</button>
<ul class="md-version__list">
${ config.versions.active.map(
(version) => `
<li class="md-version__item">
<a href="${ version.urls.documentation }" class="md-version__link">
${ version.slug }
</a>
</li>`).join("\n")}
</ul>
</div>`;
document.querySelector(".md-header__topic").insertAdjacentHTML("beforeend", versioning);
}); |
I think this happens because you have "Instant loading" enabled in your project at https://github.com/PlasmaFAIR/fortitude/blob/main/mkdocs.yml#L12C7-L12C25 If you disable that, it should work without issues. To keep that feature enabled, the JS code has to be modified to avoid re-adding the version selector if it's already added, or -- delete the version selector and re-add it to avoid duplication. |
My javascript is pretty poor, I have tried inserting: document.querySelector(".md-version").remove(); just before the |
@ZedThree I opened a PR that removes the old versions before re-adding them. Can you give it a try? |
Closes #12032 <!-- readthedocs-preview docs start --> --- :books: Documentation previews :books: - User's documentation (`docs`): https://docs--12142.org.readthedocs.build/12142/ <!-- readthedocs-preview docs end --> <!-- readthedocs-preview dev start --> - Developer's documentation (`dev`): https://dev--12142.org.readthedocs.build/12142/ <!-- readthedocs-preview dev end --> --------- Co-authored-by: Anthony <[email protected]>
Details
Actual Result
When I click links in the left-hand nav pane, a new version drop-down menu (
<div class=md-version>
) appears in the top nav bar:This doesn't happen locally, as this is the RTD inserted menu.
Expected Result
Just one drop-menu version menu stays there.
The text was updated successfully, but these errors were encountered: