Skip to content

Commit

Permalink
excluding yaml config files in build output but allowing other files …
Browse files Browse the repository at this point in the history
…like images. Fixed issue #16
  • Loading branch information
jdoiro3 committed Apr 8, 2022
1 parent 80ecd65 commit a453f73
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 43 deletions.
Empty file.
10 changes: 10 additions & 0 deletions __tests__/fixtures/parent-with-imported-images/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -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


89 changes: 49 additions & 40 deletions __tests__/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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."
}

Expand All @@ -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"
}
9 changes: 6 additions & 3 deletions mkdocs_multirepo_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions mkdocs_multirepo_plugin/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a453f73

Please sign in to comment.