diff --git a/jweb/context.py b/jweb/context.py index 7e115a6..91b418c 100644 --- a/jweb/context.py +++ b/jweb/context.py @@ -105,6 +105,7 @@ class Context: def __write(self, content: Content) -> Path: relative_path = content.path.relative_to(self.__content_directory) output_path = self.__output_directory / relative_path + output_path.parent.mkdir(parents=True, exist_ok=True) with output_path.open("w") as output_file: output_file.write(content.data) diff --git a/tests/test_context.py b/tests/test_context.py index 4208402..bc6783d 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -49,8 +49,11 @@ def test_write(datadir: Path) -> None: with open(datadir / "build" / "content.txt", encoding="utf-8") as ouput_file: assert ouput_file.read() == "Otters\n" + with open(datadir / "build/subdir/content.txt", encoding="utf-8") as ouput_file: + assert ouput_file.read() == "Weasel\n" + with open(datadir / "build" / "output.html", encoding="utf-8") as ouput_file: - assert ouput_file.read() == "/content.txt" + assert ouput_file.read() == "/content.txt\n/subdir/content.txt" def test_glob(datadir: Path) -> None: diff --git a/tests/test_context/content/subdir/content.txt b/tests/test_context/content/subdir/content.txt new file mode 100644 index 0000000..62214c4 --- /dev/null +++ b/tests/test_context/content/subdir/content.txt @@ -0,0 +1 @@ +Weasel diff --git a/tests/test_context/src/test-write.html b/tests/test_context/src/test-write.html index 6b1f13c..384fc5b 100644 --- a/tests/test_context/src/test-write.html +++ b/tests/test_context/src/test-write.html @@ -1 +1,2 @@ {{ 'content.txt' | load | write }} +{{ 'subdir/content.txt' | load | write }}