You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Adding the same page multiple times results in strange navigation #3428
Clicking on the None headings does not highlight them, only the "last" in the list.
I'm unsure if this is supposed to be supported, but I think that at a minimum a better error message during build could be useful to officially disallow this if it's not supported.
It's not obvious eg. how "next"/"prev" could possibly work in this context, so it seems like a broken case to me.
My expected optimal behavior here is probably one of...
Ignore it. Edge cases might do edgy things. C'est la vie. - The "don't add the same page multiple times" comment above might be taken as a little flippant, but it's actually sensible advice.
Raise an error.
Is there a different behavior here that I'm missing, that we should prefer?
It's been a while since I reported this, but I think raising an error (or warning since users can opt into treating warnings as errors) rather than silently producing inconsistent results would be best for the user IMO. That helps the user catch mistakes like this in CI.
A solution is to use pymdownx.snippets to re-use/include the same content in every page. Example:
create foo.md, bar.md, baz.md
write real contents in foo.md
write --8<-- "foo.md" in bar.md and baz.md (update path to foo depending on your snippets config, see the extension docs)
@squidfunk let me know that this could cause ranking issue with search engines since the contents of the three pages is duplicated. He suggests the following to bypass it:
use a custom canonical front-matter property in bar.md and baz.md like:
---canonical: foo.md---
use the on_page_context hook to resolve "foo.md" to the right URL using the Files collection
set the Page.canonical_url of the bar and baz pages
IIUC themes then handle the rest, setting the right header metadata on the HTML page for search engines and their ranking algorithms
We consider this use-case to be out of scope for MkDocs core, so we'll recommend the solution above, but we could maybe indeed also add a warning when the same page is referenced more than once in the navigation. However that opens us up to broken builds if some users are already referencing the same page multiple times and fixing the resulting issue their own way 🤔 Then we'll have to add a validation setting to tune down the warning into an info log. That's more work than what we can put into MkDocs right now for a use-case that seems rare enough, so we'll close as out of scope, but feel free to comment further and ask to re-open if you'd like to work on this (adding a warning/validation).
Activity
oprypin commentedon Oct 16, 2023
rachel-rigdon-sp commentedon Dec 21, 2023
My team is also experiencing this issue. Is there a resolution?
oprypin commentedon Dec 21, 2023
rachel-rigdon-sp commentedon Dec 23, 2023
That is a workaround, not a resolution. If it is not technically feasible, then perhaps this issue should be closed to reflect that.
lovelydinosaur commentedon Apr 15, 2024
It's not obvious eg. how "next"/"prev" could possibly work in this context, so it seems like a broken case to me.
My expected optimal behavior here is probably one of...
Is there a different behavior here that I'm missing, that we should prefer?
johnthagen commentedon Apr 15, 2024
It's been a while since I reported this, but I think raising an error (or warning since users can opt into treating warnings as errors) rather than silently producing inconsistent results would be best for the user IMO. That helps the user catch mistakes like this in CI.
trel commentedon Apr 15, 2024
Or at minimum, a warning. There could be a real use case that would be prevented by raising an error.
pawamoy commentedon Apr 17, 2024
A solution is to use
pymdownx.snippetsto re-use/include the same content in every page. Example:foo.md,bar.md,baz.mdfoo.md--8<-- "foo.md"inbar.mdandbaz.md(update path to foo depending on your snippets config, see the extension docs)@squidfunk let me know that this could cause ranking issue with search engines since the contents of the three pages is duplicated. He suggests the following to bypass it:
use a custom
canonicalfront-matter property inbar.mdandbaz.mdlike:use the
on_page_contexthook to resolve "foo.md" to the right URL using theFilescollectionset the
Page.canonical_urlof the bar and baz pagesIIUC themes then handle the rest, setting the right header metadata on the HTML page for search engines and their ranking algorithms
We consider this use-case to be out of scope for MkDocs core, so we'll recommend the solution above, but we could maybe indeed also add a warning when the same page is referenced more than once in the navigation. However that opens us up to broken builds if some users are already referencing the same page multiple times and fixing the resulting issue their own way 🤔 Then we'll have to add a validation setting to tune down the warning into an info log. That's more work than what we can put into MkDocs right now for a use-case that seems rare enough, so we'll close as out of scope, but feel free to comment further and ask to re-open if you'd like to work on this (adding a warning/validation).