-
Notifications
You must be signed in to change notification settings - Fork 28
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
Feature idea: force redirects #71
Comments
Hi @WilliamDEdwards 🙂 I'm not sure to understand. You're talking about links to external sites right? If the external site doesn't setup a redirect, then yes, you're doomed. You can detect that the link is now broken, for example with linkchecker, but you won't know how to update it. Therefore I'm not sure why we're even discussing this here as mkdocs-redirect has absolutely no way of solving that 😅 |
Hi @pawamoy, No, I'm talking about links to mkdocs sites. Sorry if I phrased things confusingly. mkdocs-redirects does a great job at redirecting A to B. But if one moves A to B, and forgets to redirect A to B, there is no way to detect that - except for a review process, which is more error-prone by definition. Anything that links to A now has a dead link. From a UX perspective, dead links - especially in documentation - are extremely frustrating. Therefore, it would be useful to enforce the existence of redirects of all links that existed on an mkdocs site - so that links to the mkdocs will never become dead. As mentioned in the issue, I don't see a viable way to do so, as mkdocs has no way of knowing which links existed. However, I at least wanted to pitch the idea, as such a feature would be very useful in practice. |
Aaaaaaaaah much clearer, thanks. And that's a really good idea, too! I think it's doable by implementing a single option: a link to a sitemap file, which we can download and use to check for missing URLs. plugins:
- redirects:
check: https://mysite.com/some-project/sitemap
redirect_maps:
old.md: new.md Example sitemap: https://pawamoy.github.io/markdown-exec/sitemap. Example code to extract URLs from the sitemap: from xml.etree import ElementTree
tree = ElementTree.parse("sitemap.xml")
urls = [elem.text for elem in tree.iter() if "loc" in elem.tag]
print("\n".join(urls)) |
Actually since we have the |
That approach assumes that wherever builds docs can access Enforcing redirects would also be useful for anchors (e.g. if a header title is renamed), but that may be somewhat out of scope for now. Thanks for thinking along! And if it helps speed things up, I can discuss donating for a bounty. |
Yep, pages themselves might not be reachable from the developer's workstation / online IDE. In that case we could imagine letting the user provide a local path to a sitemap file, and they'd be responsible for downloading it to their workstation / uploading it to their online IDE / tracking it with Git / caching it somewhere. Supporting anchors would require more work indeed. It wouldn't be that hard though, so maybe could be done at once. We would generate a file with URLs and their anchors, that we can download again (as explained previously) to check against current build. def register_anchors(self, url, anchors: Sequence[AnchorLink]) -> None:
for anchor in anchors:
self._urls.append(f"{page.url}#{anchor.id}")
self.register_anchors(url, anchor.children)
def on_page_content(self, html: str, page: Page, **kwargs: Any) -> str:
self._urls.append(page.url)
self.register_anchors(page.url, page.toc.items)
return html |
Expectation
Site A:
Documentation:
look-here
moved tolook-over-there
.look-here
is redirected tolook-over-there
usingmkdocs-redirects
.Reality
Site A:
Documentation:
look-here
moved tolook-over-there
.look-here
is not redirected tolook-over-there
usingmkdocs-redirects
, because someone forgot.Site A now has a dead link.
What aren't solutions?
Practical
I have no ideas as to how this could be implemented in practice. After all, mkdocs has no state, so no way to know which links used to exist, and now don't, ergo which links need a redirect.
The text was updated successfully, but these errors were encountered: