diff --git a/__tests__/fixtures/parent-with-imported-images/docs/index.md b/__tests__/fixtures/parent-with-imported-images/docs/index.md new file mode 100644 index 0000000..e69de29 diff --git a/__tests__/fixtures/parent-with-imported-images/mkdocs.yml b/__tests__/fixtures/parent-with-imported-images/mkdocs.yml new file mode 100644 index 0000000..99d68f5 --- /dev/null +++ b/__tests__/fixtures/parent-with-imported-images/mkdocs.yml @@ -0,0 +1,10 @@ +site_name: Test + +nav: + - Home: index.md + - ok-with-images: '!import https://github.com/jdoiro3/mkdocs-multirepo-demoRepo1?branch=ok-with-images' + +plugins: + - multirepo + + diff --git a/__tests__/test.bats b/__tests__/test.bats index fa04c71..4eeef6e 100644 --- a/__tests__/test.bats +++ b/__tests__/test.bats @@ -13,15 +13,13 @@ fixturesDir=${rootDir}/__tests__/fixtures debugger() { echo "--- STATUS ---" - if [ $status -eq 0 ] - then + if [ $status -eq 0 ]; then echo "Successful Status Code ($status)" else echo "Failed Status Code ($status)" fi echo "--- OUTPUT ---" echo $output - echo "--------------" } outputContains() { @@ -37,19 +35,22 @@ outputContains() { } assertFileExists() { - run cat $1 - if [ "$status" -eq 0 ] - then + if test -f "$1"; then return 0 else + echo "$1 does not exist" + echo "--- Site Directory Contents ---" find $parent/site return 1 fi } assertFileDoesntExist() { - run cat $1 - [ "$status" -eq 1 ] + if ! test -f "$1"; then + return 0 + else + return 1 + fi } assertFileContains() { @@ -85,89 +86,89 @@ teardown() { # Test suites. # -@test "builds a mkdocs site with repos section" { +@test "Build a mkdocs site with repos section" { cd ${fixturesDir} parent="parent-with-repos" run mkdocs build --config-file=$parent/mkdocs.yml debugger - run cat $parent/site/ok-nav-simple/index.html + run cat "$parent/site/ok-nav-simple/index.html" outputContains "Welcome to a simple repo." - run cat $parent/site/ok-no-nav/index.html + run cat "$parent/site/ok-no-nav/index.html" outputContains "I'm an okay setup with no nav configured in the imported repo." - run cat $parent/site/ok-nav-complex/index.html + run cat "$parent/site/ok-nav-complex/index.html" outputContains "Welcome to a complex repo." - run cat $parent/site/ok-nav-complex/section1/getting-started/index.html + run cat "$parent/site/ok-nav-complex/section1/getting-started/index.html" outputContains "Let's get started with section 1." - run cat $parent/site/ok-nav-complex/section2/getting-started/index.html + run cat "$parent/site/ok-nav-complex/section2/getting-started/index.html" outputContains "Let's get started with section 2." - run cat $parent/site/ok-nav-complex/section1/index.html + run cat "$parent/site/ok-nav-complex/section1/index.html" outputContains "Welcome to section 1." - run cat $parent/site/ok-nav-complex/section2/index.html + run cat "$parent/site/ok-nav-complex/section2/index.html" outputContains "Welcome to section 2." } -@test "builds a mkdocs site with nav section" { +@test "Build a mkdocs site with nav section" { cd ${fixturesDir} parent="parent-with-nav" run mkdocs build --config-file=$parent/mkdocs.yml debugger - assertFileExists $parent/site/ok-nav-simple/index.html - run cat $parent/site/ok-nav-simple/index.html + assertFileExists "$parent/site/ok-nav-simple/index.html" + run cat "$parent/site/ok-nav-simple/index.html" outputContains "Welcome to a simple repo." } -@test "builds a mkdocs site with nav section using material's indexes nav" { +@test "Build a mkdocs site with nav section using material's indexes nav" { cd ${fixturesDir} parent="parent-with-indexes-nav" run mkdocs build --config-file=$parent/mkdocs.yml debugger - assertFileExists $parent/site/ok-nav-simple/index.html - run cat $parent/site/ok-nav-simple/index.html + assertFileExists "$parent/site/ok-nav-simple/index.html" + run cat "$parent/site/ok-nav-simple/index.html" outputContains "Welcome to a simple repo." } -@test "builds a mkdocs site with a different config file name and location" { +@test "Build a mkdocs site with a different config file name and location" { cd ${fixturesDir} parent="parent-config-test" run mkdocs build --config-file=$parent/mkdocs.yml debugger - assertFileExists $parent/site/section/index.html - run cat $parent/site/section/index.html + assertFileExists "$parent/site/section/index.html" + run cat "$parent/site/section/index.html" outputContains "I'm okay even though my config file is outside the docs folder and is called multirepo.yml" } -@test "builds a mkdocs site with multiple imports in nav section" { +@test "Build a mkdocs site with multiple imports in nav section" { cd ${fixturesDir} parent="parent-multiple-nav-imports" run mkdocs build --config-file=$parent/mkdocs.yml debugger - run cat $parent/site/ok-nav-simple/index.html + run cat "$parent/site/ok-nav-simple/index.html" outputContains "Welcome to a simple repo." - run cat $parent/site/ok-nav-complex/index.html + run cat "$parent/site/ok-nav-complex/index.html" outputContains "Welcome to a complex repo." - run cat $parent/site/ok-nav-complex/section1/getting-started/index.html + run cat "$parent/site/ok-nav-complex/section1/getting-started/index.html" outputContains "Let's get started with section 1." - run cat $parent/site/ok-nav-complex/section2/getting-started/index.html + run cat "$parent/site/ok-nav-complex/section2/getting-started/index.html" outputContains "Let's get started with section 2." - run cat $parent/site/ok-nav-complex/section1/index.html + run cat "$parent/site/ok-nav-complex/section1/index.html" outputContains "Welcome to section 1." - run cat $parent/site/ok-nav-complex/section2/index.html + run cat "$parent/site/ok-nav-complex/section2/index.html" outputContains "Welcome to section 2." # testing subsection import - run cat $parent/site/ok-nav-simple2/index.html + run cat "$parent/site/ok-nav-simple2/index.html" outputContains "Welcome to a simple repo." - run cat $parent/site/ok-nav-complex2/index.html + run cat "$parent/site/ok-nav-complex2/index.html" outputContains "Welcome to a complex repo." - run cat $parent/site/ok-nav-complex2/section1/getting-started/index.html + run cat "$parent/site/ok-nav-complex2/section1/getting-started/index.html" outputContains "Let's get started with section 1." - run cat $parent/site/ok-nav-complex2/section2/getting-started/index.html + run cat "$parent/site/ok-nav-complex2/section2/getting-started/index.html" outputContains "Let's get started with section 2." - run cat $parent/site/ok-nav-complex2/section1/index.html + run cat "$parent/site/ok-nav-complex2/section1/index.html" outputContains "Welcome to section 1." - run cat $parent/site/ok-nav-complex2/section2/index.html + run cat "$parent/site/ok-nav-complex2/section2/index.html" outputContains "Welcome to section 2." # testing an import within multiple subsections - run cat $parent/site/ok-nav-simple3/index.html + run cat "$parent/site/ok-nav-simple3/index.html" outputContains "Welcome to a simple repo." } @@ -176,5 +177,13 @@ teardown() { parent="parent-confirm-no-mkdocs.yml" run mkdocs build --config-file=$parent/mkdocs.yml debugger - assertFileDoesntExist $parent/site/DemoRepo/mkdocs.yml + assertFileDoesntExist "$parent/site/DemoRepo/mkdocs.yml" +} + +@test "Make sure imported repo's with images are included in build output" { + cd ${fixturesDir} + parent="parent-with-imported-images" + run mkdocs build --config-file=$parent/mkdocs.yml + debugger + assertFileExists "$parent/site/ok-with-images/assets/images/zelda-dark-world.png" } diff --git a/mkdocs_multirepo_plugin/plugin.py b/mkdocs_multirepo_plugin/plugin.py index bda6d8d..695122c 100644 --- a/mkdocs_multirepo_plugin/plugin.py +++ b/mkdocs_multirepo_plugin/plugin.py @@ -5,9 +5,12 @@ from mkdocs.config import Config, config_options from .structure import ( Repo, DocsRepo, parse_repo_url, batch_import, resolve_nav_paths, - get_import_stmts + get_import_stmts, is_yaml_file ) -from .util import ImportDocsException, log, get_src_path_root, asyncio_run +from .util import ( + ImportDocsException, log, get_src_path_root, + asyncio_run +) from pathlib import Path from copy import deepcopy import shutil @@ -160,7 +163,7 @@ def on_files(self, files: Files, config: Config) -> Files: temp_config["docs_dir"] = self.temp_dir other_repo_files = get_files(temp_config) for f in other_repo_files: - if f.is_documentation_page(): + if not is_yaml_file(f): files.append(f) return files diff --git a/mkdocs_multirepo_plugin/structure.py b/mkdocs_multirepo_plugin/structure.py index 8e58b5e..6758b6b 100644 --- a/mkdocs_multirepo_plugin/structure.py +++ b/mkdocs_multirepo_plugin/structure.py @@ -3,12 +3,21 @@ import subprocess from pathlib import Path from mkdocs.utils import yaml_load +from mkdocs.structure.files import File from .util import ( ImportDocsException, git_supports_sparse_clone, remove_parents, execute_bash_script ) import asyncio import tqdm +import os + + +def is_yaml_file(file: File) -> bool: + return os.path.splitext(file.src_path)[1] in ( + ".yaml", + ".yml" + ) def resolve_nav_paths(nav: List[Dict], section_name: str) -> None: