backstage / mkdocs-monorepo-plugin

✚ Build multiple documentation folders in a single Mkdocs. Designed for large codebases.
https://backstage.github.io/mkdocs-monorepo-plugin/
Apache License 2.0
313 stars 75 forks source link

edit_uri incorrect for included projects whose site_name includes directory separator #127

Open duncanmmacleod opened 1 month ago

duncanmmacleod commented 1 month ago

This is a great plugin, thank you for providing and maintaining it!

I am using this plugin to embed third-party docs projects 'deep' (not at the top-level) in the hierarchy, like this:

site_name: "Test example"
repo_url: 'https://example.com/level1'
edit_uri: 'edit/docs'

nav:
  - Top: index.md
  - Level 1:
    - Level 1: level1/index.md
    - Level 2: '!include projects/level2/mkdocs.yml'

theme:
  name: 'material'
  features:
    - content.action.edit
    - content.action.view

plugins:
  - monorepo

where projects/level2 is a git submodule linked to a separate project whose mkdocs.yml looks like this:

site_name: 'level1/level2'
repo_url: 'https://example.com/level2'
edit_uri: 'edit/docs'
nav:
  - index.md

This results in the projects/level2/docs/index.md file in the git tree rendering at level1/level2/index.html in the site HTML tree, which is what I want. However, in this case, the edit_url for the the level2/docs/index.md file is rendered as:

https://example.com/level2/edit/docs/level2/index.md

This is incorrect, it should be

https://example.com/level2/edit/docs/index.md

All of this is available on github at https://github.com/duncanmmacleod/mkdocs-monorepo-plugin-edit_uri-example.

If this isn't an improper use of the plugin (please just tell me if this is the case), I think the fix should be

diff --git a/mkdocs_monorepo_plugin/edit_uri.py b/mkdocs_monorepo_plugin/edit_uri.py
index 4b0bbe5..a6b84d7 100644
--- a/mkdocs_monorepo_plugin/edit_uri.py
+++ b/mkdocs_monorepo_plugin/edit_uri.py
@@ -43,7 +43,7 @@ class EditUrl:
     return path.relpath(abs_page_config_file_dir, abs_root_config_file_dir)

   def __get_page_src_path(self):
-    alias = self.page.url.split('/')[0]
+    alias = self.__get_page_dir_alias()
     path = self.page.file.src_path
     return path.replace('{}/'.format(alias), '')

but I don't really understand the implications of this change on other use cases. I'm attempting to manipulate the __tests__ to reproduce this configuration and hope to be able to post a merge request including the patch.