Skip to content

Commit

Permalink
edit_uri: fix edit URL for nested site_name
Browse files Browse the repository at this point in the history
fixes backstage#127 and adds regression test for nested site_name in included project
  • Loading branch information
duncanmmacleod committed May 21, 2024
1 parent b1965a2 commit ee1c26c
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# API Documentation

Some sub documentation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Other Documentation
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
site_name: "test/api"
site_description: "This is an api."
repo_url: https://github.com/backstage/mkdocs-monorepo-plugin
edit_uri: edit/master/__tests__/integration/fixtures/ok-include-path-edit-uri-nested/api/docs/

plugins:
- monorepo

nav:
- Home: index.md
- Other: other/other.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Top Level Project Documentation

Some higher level info about the project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Other Documentation
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
site_name: "Example"
site_description: "Description Here"
repo_url: https://github.com/backstage/mkdocs-monorepo-plugin
edit_uri: edit/master/__tests__/integration/fixtures/ok-include-path-edit-uri-nested/docs/

plugins:
- monorepo

nav:
- Home: "index.md"
- Other: "other.md"
- API: "!include api/mkdocs.yml"
9 changes: 9 additions & 0 deletions __tests__/integration/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@ teardown() {
assertFileContains './site/test/other/other/index.html' 'href="https://github.com/backstage/mkdocs-monorepo-plugin/edit/master/__tests__/integration/fixtures/ok-include-path-edit-uri/api/docs/other/other.md"'
}

@test "sets edit url for nested included path pages" {
cd ${fixturesDir}/ok-include-path-edit-uri-nested
assertSuccessMkdocs build

assertFileContains './site/index.html' 'href="https://github.com/backstage/mkdocs-monorepo-plugin/edit/master/__tests__/integration/fixtures/ok-include-path-edit-uri-nested/docs/index.md"'
assertFileContains './site/test/api/index.html' 'href="https://github.com/backstage/mkdocs-monorepo-plugin/edit/master/__tests__/integration/fixtures/ok-include-path-edit-uri-nested/api/docs/index.md"'
assertFileContains './site/test/api/other/other/index.html' 'href="https://github.com/backstage/mkdocs-monorepo-plugin/edit/master/__tests__/integration/fixtures/ok-include-path-edit-uri-nested/api/docs/other/other.md"'
}

@test "sets edit url for included wildcard pages" {
cd ${fixturesDir}/ok-include-wildcard-edit-uri
assertSuccessMkdocs build
Expand Down
2 changes: 1 addition & 1 deletion mkdocs_monorepo_plugin/edit_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __get_page_docs_dir(self):
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), '')

Expand Down

0 comments on commit ee1c26c

Please sign in to comment.