fix: fix creation of parent directory of written content files
This commit is contained in:
parent
e98344e0a0
commit
bdcb460a02
|
|
@ -105,6 +105,7 @@ class Context:
|
||||||
def __write(self, content: Content) -> Path:
|
def __write(self, content: Content) -> Path:
|
||||||
relative_path = content.path.relative_to(self.__content_directory)
|
relative_path = content.path.relative_to(self.__content_directory)
|
||||||
output_path = self.__output_directory / relative_path
|
output_path = self.__output_directory / relative_path
|
||||||
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
with output_path.open("w") as output_file:
|
with output_path.open("w") as output_file:
|
||||||
output_file.write(content.data)
|
output_file.write(content.data)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,11 @@ def test_write(datadir: Path) -> None:
|
||||||
with open(datadir / "build" / "content.txt", encoding="utf-8") as ouput_file:
|
with open(datadir / "build" / "content.txt", encoding="utf-8") as ouput_file:
|
||||||
assert ouput_file.read() == "Otters\n"
|
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:
|
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:
|
def test_glob(datadir: Path) -> None:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Weasel
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
{{ 'content.txt' | load | write }}
|
{{ 'content.txt' | load | write }}
|
||||||
|
{{ 'subdir/content.txt' | load | write }}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue