Replies: 3 comments 4 replies
-
What I do on the official docs is use the redirects plugin when I move pages, which should also fulfill most of your requirements. It does not work with anchors (yet?) which I already reported in mkdocs/mkdocs-redirects#16, but it should be enough for most cases. Thus, when moving a page, always create a redirect: Lines 92 to 98 in 88cfda4 |
Beta Was this translation helpful? Give feedback.
-
Hi @MrF3lix,
---
context_ids:
- 30c6926f-ae00-48d6-b823-5ec25aa05031
_description: 'Description'
---
# Alerts
{
"30c6926f-ae00-48d6-b823-5ec25aa05031": "Alerts/",
We now try to always use the following URL format (using the example above): Hope that gives you some implementation ideas @squidfunk, happy to share the code with you if you want to implement it in your implementation at some point! |
Beta Was this translation helpful? Give feedback.
-
the latest version of the hook with minor bugfixing: import logging
import mkdocs.plugins
import os
log = logging.getLogger('mkdocs')
@mkdocs.plugins.event_priority(-50)
def on_page_content(html, page, config, files):
redirect_plugin = config.get('plugins', {}).get('redirects')
redirects = redirect_plugin.config.get('redirect_maps',{})
if "context_id" in page.meta:
context_id = page.meta.get("context_id")
key = f"{context_id}.md"
if key in redirects:
log_context_id_warning(page.meta.context_id, page.file.src_path.replace(os.sep, "/"), redirects[key])
redirects[key] = page.file.src_path.replace(os.sep, "/")
for item in page.toc.items:
add_redirect(item, page, redirects)
def add_redirect(item, page, redirects):
if item.id.isdigit():
key = f"{item.id}.md"
if key in redirects:
log_context_id_warning(item.id, page.file.src_path.replace(os.sep, "/"), redirects[key])
redirects[key] = f"{page.file.src_path}{item.url}".replace(os.sep, "/")
for child in item.children:
add_redirect(child, page, redirects)
def log_context_id_warning(context_id, markdown1, markdown2):
log.warning(f"Context ID {context_id} used in {markdown1} and {markdown2}") |
Beta Was this translation helpful? Give feedback.
-
Hi, at my work we've been using mkdocs and mkdocs-material now for a while on multiple documentation pages and we're very happy with how easy and flexible it is!
We reference our documentation pages quite a lot in PDFs, chats, and other documentation sites. Since a while I noticed that some of our links get outdated because pages get moved, renamed or deleted.
I've been wondering, is there a way around this?
I know that there are external services like Perma.cc or PermanentLink but I'd like to prevent using an external service.
So my questions would be:
Beta Was this translation helpful? Give feedback.
All reactions