Skip to content

set_edit_path() has no effect when edit_uri_template is used #37

@frankkusters

Description

@frankkusters

I'm using the Mkdocs option edit_uri_template, which is mutually exclusive with edit_uri.

set_edit_path() has no effect in my setup (the page.edit_url remains empty). It's caused by this section:

def on_page_content(self, html, page: Page, config: Config, files: Files):
repo_url = config.get("repo_url", None)
edit_uri = config.get("edit_uri", None)
src_path = pathlib.PurePath(page.file.src_path).as_posix()
if src_path in self._edit_paths:
path = self._edit_paths.pop(src_path)
if repo_url and edit_uri:
# Ensure urljoin behavior is correct

With mkdocs 1.6, it is possible to set file.edit_uri:
Enabling true generated files and expanding the File API

I'm not sure what version of mkdocs you are targeting. For now I'm working around it with this hook:

def on_files(files: Files, config: MkDocsConfig, **kwargs) -> Files:
    edit_paths = config.plugins['gen-files']._edit_paths
    for src_uri in list(edit_paths.keys()):
        edit_uri = edit_paths.pop(src_uri)
        files.get_file_from_path(src_uri).edit_uri = edit_uri
    return files

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions