From e0a2d2b83cff679959fbf1f2b16ea86f3bb1b5c8 Mon Sep 17 00:00:00 2001 From: jgrogan Date: Mon, 18 Nov 2024 20:47:20 +0000 Subject: [PATCH] Further small cleaning of generate script --- src/dialann/site_generator.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/dialann/site_generator.py b/src/dialann/site_generator.py index b90c02c..5fe2435 100644 --- a/src/dialann/site_generator.py +++ b/src/dialann/site_generator.py @@ -37,11 +37,15 @@ def _read_file(path: Path) -> str: return f.read() +def _get_transformed_path(config: Config, path: Path, ext: str) -> str: + source_dir = path.parent.relative_to(config.source_dir) + filename = str(path.stem) + f".{ext}" + return config.build_dir / source_dir / filename + + def generate(config: Config): - static_dir = config.source_dir / "static" - build_static_dir = config.build_dir / "static" - _replace_content(static_dir, build_static_dir) + _replace_content(config.source_dir / "static", config.build_dir / "static") template_dir = config.source_dir / "templates" header = _read_if_exists(template_dir / "header.html") @@ -49,11 +53,8 @@ def generate(config: Config): parser = MarkdownIt() sources = config.source_dir.glob("**/*.md") - for source in sources: - source_dir = source.parent.relative_to(config.source_dir) - output_path = config.build_dir / source_dir / (str(source.stem) + ".html") - content = _read_file(source) output = parser.render(content) + output_path = _get_transformed_path(config, source, "html") _write_file(output_path, header + output + footer)