Skip to content
Discussion options

You must be logged in to vote

Thank you! This was very useful. For anyone interested, that's the code of the hook that worked for me:

"""
Replaces `repo_url` and `edit_uri` settings defined in .meta.yml files.
"""

import mkdocs.plugins

@mkdocs.plugins.event_priority(-50)
def on_page_context(context, page, config, nav):
    if "repo_url" in page.meta:
        config.repo_url = page.meta["repo_url"]

    if "edit_uri" in page.meta:
        config.edit_uri = page.meta["edit_uri"]

    if "repo_url" in page.meta or "edit_uri" in page.meta:
        page.edit_url = f"{config.repo_url.rstrip('/')}/{config.edit_uri}{page.file.src_uri}"

    return context

I had to manually build page.edit_url by concatenating config.repo_url

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@squidfunk
Comment options

@kamilkrzyskow
Comment options

@pereorga
Comment options

Answer selected by squidfunk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #7937 on January 29, 2025 02:36.