1
0
Fork 0
mirror of https://github.com/Findus23/lw1.at.git synced 2024-09-09 04:03:45 +02:00
lw1.at/lw1/writer.py
2022-04-26 17:31:08 +02:00

22 lines
669 B
Python

from pathlib import Path
from lw1.file import Image
from lw1.paths import output_dir
class Writer:
def write(self, url: Path, html: str, direct=False):
output_url = output_dir / url.relative_to("/")
print(url)
if not direct:
output_url.mkdir(exist_ok=True, parents=True)
output_file = output_url / "index.html"
else:
output_file = output_url
with output_file.open("w") as f:
f.write(html)
def writeImage(self, url: Path, image: Image):
image_file = output_dir / url
image_file.parent.mkdir(exist_ok=True, parents=True)
image.copy_to(image_file)