diff --git a/__tests__/integration/fixtures/error-no-nav-no-docs/project-a/mkdocs.yml b/__tests__/integration/fixtures/error-no-nav-no-docs/project-a/mkdocs.yml deleted file mode 100644 index 8dcc285..0000000 --- a/__tests__/integration/fixtures/error-no-nav-no-docs/project-a/mkdocs.yml +++ /dev/null @@ -1,7 +0,0 @@ -site_name: 'test' -site_description: 'This is a subdomain site.' - -plugins: - - monorepo - -docs_dir: docs diff --git a/__tests__/integration/fixtures/error-no-nav-no-docs/docs/index.md b/__tests__/integration/fixtures/ok-no-nav-no-dir/docs/index.md similarity index 100% rename from __tests__/integration/fixtures/error-no-nav-no-docs/docs/index.md rename to __tests__/integration/fixtures/ok-no-nav-no-dir/docs/index.md diff --git a/__tests__/integration/fixtures/error-no-nav-no-docs/mkdocs.yml b/__tests__/integration/fixtures/ok-no-nav-no-dir/mkdocs.yml similarity index 100% rename from __tests__/integration/fixtures/error-no-nav-no-docs/mkdocs.yml rename to __tests__/integration/fixtures/ok-no-nav-no-dir/mkdocs.yml diff --git a/__tests__/integration/fixtures/ok-no-nav-no-dir/project-a/docs/README.md b/__tests__/integration/fixtures/ok-no-nav-no-dir/project-a/docs/README.md new file mode 100644 index 0000000..4104f83 --- /dev/null +++ b/__tests__/integration/fixtures/ok-no-nav-no-dir/project-a/docs/README.md @@ -0,0 +1,3 @@ +# Hello world! + +This contains a sentence which only exists in the ok/project-a fixture. diff --git a/__tests__/integration/fixtures/ok-no-nav-no-dir/project-a/mkdocs.yml b/__tests__/integration/fixtures/ok-no-nav-no-dir/project-a/mkdocs.yml new file mode 100644 index 0000000..ea06b35 --- /dev/null +++ b/__tests__/integration/fixtures/ok-no-nav-no-dir/project-a/mkdocs.yml @@ -0,0 +1,5 @@ +site_name: "test" +site_description: "This is a subdomain site." + +plugins: + - monorepo diff --git a/__tests__/integration/test.bats b/__tests__/integration/test.bats index 2f6ac6f..0fee968 100644 --- a/__tests__/integration/test.bats +++ b/__tests__/integration/test.bats @@ -103,6 +103,13 @@ teardown() { [[ "$output" == *"This contains a sentence which only exists in the ok/project-a fixture."* ]] } +@test "builds a mkdocs site with no nav and no docs_dir key" { + cd ${fixturesDir}/ok-no-nav-no-dir + assertSuccessMkdocs build + assertFileExists site/test/index.html + [[ "$output" == *"This contains a sentence which only exists in the ok/project-a fixture."* ]] +} + @test "builds a mkdocs site with yaml extension" { cd ${fixturesDir}/ok-yaml-not-yml assertSuccessMkdocs build @@ -227,12 +234,6 @@ teardown() { [[ "$output" == *"[mkdocs-monorepo] The /"*"/__tests__/integration/fixtures/error-include-path-no-docs-folder/project-a/docs path is not valid. Please update your 'nav' with a valid path."* ]] } -@test "fails if !include path docs_dir does not contain any files" { - cd ${fixturesDir}/error-no-nav-no-docs - assertFailedMkdocs build - [[ "$output" == *"[mkdocs-monorepo] The file path /"*"/__tests__/integration/fixtures/error-no-nav-no-docs/project-a/mkdocs.yml does not contain a valid 'nav' key in the YAML file. Please include it to indicate how your documentation should be presented in the navigation, or include a 'docs_dir' to indicate that automatic nav generation should be used."* ]] -} - @test "fails if absolute links aren't supported" { cd ${fixturesDir}/include-path-absolute-url assertSuccessMkdocs build diff --git a/mkdocs_monorepo_plugin/parser.py b/mkdocs_monorepo_plugin/parser.py index 5f00a8e..4a80d5d 100644 --- a/mkdocs_monorepo_plugin/parser.py +++ b/mkdocs_monorepo_plugin/parser.py @@ -185,8 +185,9 @@ class IncludeNavLoader: # This will check if there is a `docs_dir` property on the `mkdocs.yml` file of # the sub folder and scaffold the `nav` property from it - if self.navYaml and 'nav' not in self.navYaml and "docs_dir" in self.navYaml: - docsDirPath = os.path.join(os.path.dirname(self.absNavPath), self.navYaml["docs_dir"]) + if self.navYaml and 'nav' not in self.navYaml: + docsDir = self.navYaml.get("docs_dir", "docs") + docsDirPath = os.path.join(os.path.dirname(self.absNavPath), docsDir) def navFromDir(path): directory = {} @@ -242,8 +243,9 @@ class IncludeNavLoader: if self.navYaml and 'nav' not in self.navYaml: log.critical( "[mkdocs-monorepo] The file path {} ".format(self.absNavPath) + - "does not contain a valid 'nav' key in the YAML file. " + - "Please include it to indicate how your documentation should be presented in the navigation, " + + "does not contain a valid 'nav' key in the YAML file " + + "and the docs folder is not the default one, i.e. `docs`. " + + "Please include the `nav` key to indicate how your documentation should be presented in the navigation, " + "or include a 'docs_dir' to indicate that automatic nav generation should be used." ) raise SystemExit(1)