From 57eba4e788a90c03278dccea408b16a32d80f56f Mon Sep 17 00:00:00 2001 From: Diego Marangoni Date: Tue, 12 Oct 2021 10:37:14 +0200 Subject: [PATCH 1/8] change getAlias to convert site_name to a slug --- mkdocs_monorepo_plugin/parser.py | 13 ++----------- requirements.txt | 1 + 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/mkdocs_monorepo_plugin/parser.py b/mkdocs_monorepo_plugin/parser.py index 0feef21..f82511c 100644 --- a/mkdocs_monorepo_plugin/parser.py +++ b/mkdocs_monorepo_plugin/parser.py @@ -15,8 +15,8 @@ import logging import os import copy -import re +from slugify import slugify from mkdocs.utils import yaml_load, warning_filter, dirname_to_title, get_markdown_title log = logging.getLogger(__name__) log.addFilter(warning_filter) @@ -205,16 +205,7 @@ def getDocsDir(self): return self.navYaml.get("docs_dir", "docs") def getAlias(self): - alias = self.navYaml["site_name"] - regex = '^[a-zA-Z0-9_\-/]+$' # noqa: W605 - - if re.match(regex, alias) is None: - log.critical( - "[mkdocs-monorepo] Site name can only contain letters, numbers, underscores, hyphens and forward-slashes. " + - "The regular expression we test against is '{}'.".format(regex)) - raise SystemExit(1) - - return alias + return slugify(self.navYaml["site_name"]) def getNav(self): return self._prependAliasToNavLinks(self.getAlias(), self.navYaml["nav"]) diff --git a/requirements.txt b/requirements.txt index f14d9d8..70e4bd4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ mkdocs>=1.1.1 mkdocs-material>=5.1.0 mkdocs-git-authors-plugin==0.3.2 mkdocs-git-revision-date-localized-plugin==0.5.0 +python-slugify==5.0.2 From b98f9b66cb69b8b66c9b410b0532e57adac47609 Mon Sep 17 00:00:00 2001 From: Diego Marangoni Date: Tue, 12 Oct 2021 10:38:10 +0200 Subject: [PATCH 2/8] Update unit tests to work with slugs --- __tests__/integration/test.bats | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/__tests__/integration/test.bats b/__tests__/integration/test.bats index 0d3bcb6..0562814 100644 --- a/__tests__/integration/test.bats +++ b/__tests__/integration/test.bats @@ -121,7 +121,7 @@ teardown() { @test "builds a mkdocs site with site_name containing slash" { cd ${fixturesDir}/ok-nested-site-name-contains-slash assertSuccessMkdocs build - assertFileExists site/plugins/example-Folder/index.html + assertFileExists site/plugins-example-folder/index.html [[ "$output" == *"This contains a sentence which only exists in the ok-nested-site-name-contains-slash/project-a fixture."* ]] } @@ -139,6 +139,11 @@ teardown() { [[ "$output" == *"This contains a sentence which only exists in the ok-mkdocs-git-revision-date-localized-plugin/project-a fixture."* ]] } +@test "builds a mkdocs even if !include path has site_name containing spaces" { + cd ${fixturesDir}/error-include-path-site-name-contains-space + assertSuccessMkdocs build +} + @test "fails if !include path is above current folder" { cd ${fixturesDir}/error-include-path-is-parent assertFailedMkdocs build @@ -151,12 +156,6 @@ teardown() { [[ "$output" == *"[mkdocs-monorepo] We currently do not support nested !include statements inside of Mkdocs."* ]] } -@test "fails if !include path has site_name containing spaces" { - cd ${fixturesDir}/error-include-path-site-name-contains-space - assertFailedMkdocs build - [[ "$output" == *"[mkdocs-monorepo] Site name can only contain letters, numbers, underscores, hyphens and forward-slashes. The regular expression we test against is '^[a-zA-Z0-9_\-/]+$'."* ]] -} - @test "fails if !include paths contains duplicate site_name values" { cd ${fixturesDir}/error-include-paths-duplicate-site-name assertFailedMkdocs build From 3f728e53caae36d8047a749f5c486e4f633382cf Mon Sep 17 00:00:00 2001 From: Diego Marangoni Date: Tue, 12 Oct 2021 10:38:29 +0200 Subject: [PATCH 3/8] Remove limitation --- docs/limitations.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/limitations.md b/docs/limitations.md index b53d44d..d347808 100644 --- a/docs/limitations.md +++ b/docs/limitations.md @@ -1,4 +1,3 @@ # Caveats / Known Design Decisions - In an included `mkdocs.yml`, you cannot have `!include`. It is only supported in the root `mkdocs.yml` -- In an included `mkdocs.yml`, your `site_name` must adhere follow the regular expression: `^[a-zA-Z0-9_\-/]+$` From 61510dcf4e072302caf1f6984cc3849ed1676fdf Mon Sep 17 00:00:00 2001 From: Diego Marangoni Date: Tue, 12 Oct 2021 10:43:08 +0200 Subject: [PATCH 4/8] Bump plugin version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f95af3e..1cd881c 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setuptools.setup( name='mkdocs-monorepo-plugin', - version='0.4.16', + version='0.4.17', description='Plugin for adding monorepository support in Mkdocs.', long_description=""" This introduces support for the !include syntax in mkdocs.yml, allowing you to import additional Mkdocs navigation. From d71cb036894365b4a842d002bac76a5ac1137234 Mon Sep 17 00:00:00 2001 From: Diego Marangoni Date: Tue, 19 Oct 2021 12:29:12 +0200 Subject: [PATCH 5/8] Slugify only if didn't match regex --- __tests__/integration/test.bats | 2 +- mkdocs_monorepo_plugin/parser.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/__tests__/integration/test.bats b/__tests__/integration/test.bats index 0562814..31e7ba1 100644 --- a/__tests__/integration/test.bats +++ b/__tests__/integration/test.bats @@ -121,7 +121,7 @@ teardown() { @test "builds a mkdocs site with site_name containing slash" { cd ${fixturesDir}/ok-nested-site-name-contains-slash assertSuccessMkdocs build - assertFileExists site/plugins-example-folder/index.html + assertFileExists site/plugins/example-Folder/index.html [[ "$output" == *"This contains a sentence which only exists in the ok-nested-site-name-contains-slash/project-a fixture."* ]] } diff --git a/mkdocs_monorepo_plugin/parser.py b/mkdocs_monorepo_plugin/parser.py index f82511c..f4cc563 100644 --- a/mkdocs_monorepo_plugin/parser.py +++ b/mkdocs_monorepo_plugin/parser.py @@ -15,6 +15,7 @@ import logging import os import copy +import re from slugify import slugify from mkdocs.utils import yaml_load, warning_filter, dirname_to_title, get_markdown_title @@ -205,7 +206,13 @@ def getDocsDir(self): return self.navYaml.get("docs_dir", "docs") def getAlias(self): - return slugify(self.navYaml["site_name"]) + alias = self.navYaml["site_name"] + regex = '^[a-zA-Z0-9_\-/]+$' # noqa: W605 + + if re.match(regex, alias) is None: + alias = slugify(self.navYaml["site_name"]) + + return alias def getNav(self): return self._prependAliasToNavLinks(self.getAlias(), self.navYaml["nav"]) From 37f7b330861f7ec6a7c2211374e2ca8f224bd4b6 Mon Sep 17 00:00:00 2001 From: Diego Marangoni Date: Tue, 19 Oct 2021 12:29:17 +0200 Subject: [PATCH 6/8] Use slugify library compatible with python 3.5 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 70e4bd4..4136355 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,4 @@ mkdocs>=1.1.1 mkdocs-material>=5.1.0 mkdocs-git-authors-plugin==0.3.2 mkdocs-git-revision-date-localized-plugin==0.5.0 -python-slugify==5.0.2 +python-slugify==4.0.1 From a1c96e38ddb160ea108637367726eb0a356f2f83 Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Wed, 27 Oct 2021 14:57:20 +0200 Subject: [PATCH 7/8] Rename test fixtures. Signed-off-by: Eric Peterson --- .../docs/index.md | 0 .../mkdocs.yml | 0 .../project-a/docs/README.md | 0 .../project-a/mkdocs.yml | 0 __tests__/integration/test.bats | 2 +- 5 files changed, 1 insertion(+), 1 deletion(-) rename __tests__/integration/fixtures/{error-include-path-site-name-contains-space => ok-include-path-site-name-contains-space}/docs/index.md (100%) rename __tests__/integration/fixtures/{error-include-path-site-name-contains-space => ok-include-path-site-name-contains-space}/mkdocs.yml (100%) rename __tests__/integration/fixtures/{error-include-path-site-name-contains-space => ok-include-path-site-name-contains-space}/project-a/docs/README.md (100%) rename __tests__/integration/fixtures/{error-include-path-site-name-contains-space => ok-include-path-site-name-contains-space}/project-a/mkdocs.yml (100%) diff --git a/__tests__/integration/fixtures/error-include-path-site-name-contains-space/docs/index.md b/__tests__/integration/fixtures/ok-include-path-site-name-contains-space/docs/index.md similarity index 100% rename from __tests__/integration/fixtures/error-include-path-site-name-contains-space/docs/index.md rename to __tests__/integration/fixtures/ok-include-path-site-name-contains-space/docs/index.md diff --git a/__tests__/integration/fixtures/error-include-path-site-name-contains-space/mkdocs.yml b/__tests__/integration/fixtures/ok-include-path-site-name-contains-space/mkdocs.yml similarity index 100% rename from __tests__/integration/fixtures/error-include-path-site-name-contains-space/mkdocs.yml rename to __tests__/integration/fixtures/ok-include-path-site-name-contains-space/mkdocs.yml diff --git a/__tests__/integration/fixtures/error-include-path-site-name-contains-space/project-a/docs/README.md b/__tests__/integration/fixtures/ok-include-path-site-name-contains-space/project-a/docs/README.md similarity index 100% rename from __tests__/integration/fixtures/error-include-path-site-name-contains-space/project-a/docs/README.md rename to __tests__/integration/fixtures/ok-include-path-site-name-contains-space/project-a/docs/README.md diff --git a/__tests__/integration/fixtures/error-include-path-site-name-contains-space/project-a/mkdocs.yml b/__tests__/integration/fixtures/ok-include-path-site-name-contains-space/project-a/mkdocs.yml similarity index 100% rename from __tests__/integration/fixtures/error-include-path-site-name-contains-space/project-a/mkdocs.yml rename to __tests__/integration/fixtures/ok-include-path-site-name-contains-space/project-a/mkdocs.yml diff --git a/__tests__/integration/test.bats b/__tests__/integration/test.bats index 31e7ba1..6ad638d 100644 --- a/__tests__/integration/test.bats +++ b/__tests__/integration/test.bats @@ -140,7 +140,7 @@ teardown() { } @test "builds a mkdocs even if !include path has site_name containing spaces" { - cd ${fixturesDir}/error-include-path-site-name-contains-space + cd ${fixturesDir}/ok-include-path-site-name-contains-space assertSuccessMkdocs build } From 802f89aac7a5bea5f676198bb64a131e18d50852 Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Wed, 27 Oct 2021 14:57:37 +0200 Subject: [PATCH 8/8] Prepare for patch release. Signed-off-by: Eric Peterson --- docs/CHANGELOG.md | 5 +++++ setup.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 6640324..fe440d7 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 0.4.18 + +- Allow inclusion of sub-docs `mkdocs.yml` even if its name isn't URL-friendly. + Works by slugifying non-URL friendly names. (#58) + ## 0.4.16 - Fix `mkdocs serve` incompatibility when running with mkdocs >= 1.2 diff --git a/setup.py b/setup.py index 1cd881c..3bb365e 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setuptools.setup( name='mkdocs-monorepo-plugin', - version='0.4.17', + version='0.4.18', description='Plugin for adding monorepository support in Mkdocs.', long_description=""" This introduces support for the !include syntax in mkdocs.yml, allowing you to import additional Mkdocs navigation.